Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
20405 Widoki

 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">

Awatar
Odrzuć

Thanks Yenthe Got it 👍

You're welcome, best of luck!

Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
mar 15
6915
3
kwi 21
8370
2
cze 20
5641
1
paź 19
4598
1
mar 15
13810