Skip to Content
Menu
This question has been flagged
2 Replies
18090 Views

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

Avatar
Discard

Thanks Yenthe Got it 👍

You're welcome, best of luck!

Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
1
Mar 15
6146
3
Apr 21
6454
2
Jun 20
4209
1
Oct 19
3568
1
Mar 15
12375