콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
20844 화면

 which one is pest practice in adding less/css/js files for the theme in the assest.xml file ?

Using 

<template id="test_style" name="Test Style" inherit_id="website.assets_frontend">
<xpath expr="link[last()]" position="after">

OR

<template id="test_style" name="Test Style" inherit_id="website.assets_frontend"> 
<xpath expr="." position="inside">

아바타
취소

Thanks Yenthe Got it 👍

You're welcome, best of luck!

베스트 답변

Hi Yazeed,

In your example it actually makes no difference at all. Both accomplish exactly the same and will have the same loading time and such. Generally speaking you should try to write xpath expressions that are as short and easy as possible. Because of this I personally always choose the second expression with <xpath expr="." position="inside">. It will add your custom file(s) into the root element of the "website.assets_frontend" bundle, which is the cleanest and shortest xpath expression that you can write. 

In your example it all doesn't matter a lot but there are quite some places where it does. Have a look at these two examples:

<xpath expr="//group/group/field[@name='field_name']" position="after"></xpath>
​<xpath expr="//field[@name='field_name']" position="after"></xpath>

Which one would you pick? I would absolutely go for the second expression. The first expression in my example can break if the first group or second group are removed or if the field is placed into another part of the view in other code. In the second example I find the element by name which can only break if the field is removed.


TLDR: Your example doesn't matter a lot but try to make xpath expressions short and easy. It is absolutely worth it to think a bit longer about your expressions for the future.

Regards,

Yenthe

아바타
취소
관련 게시물 답글 화면 활동
1
3월 15
7195
3
4월 21
8869
2
6월 20
5958
1
10월 19
4870
1
3월 15
14148