XF 1.4 It is possible to use conditionals by creating an external JavaScript file?

Dylan V

Well-known member
Hello,

I'd like that my JavaScript code is not placed in the template of my style, but rather in an external JavaScript file located in the folder of my style. I've tried to use a condition in the external file, but it doesn't work (it works only if the code is in the template of the style). So, it is possible to use conditionals by creating an external JavaScript file?
 
I can't say I totally understand what you're trying to accomplish. The JS files are just JS. You can't use template syntax in them.
 
I can't say I totally understand what you're trying to accomplish. The JS files are just JS. You can't use template syntax in them.
Yes, that was what I wanted to know. I wanted to know if it was possible to use a condition in an external file other than the template of the style.

Example:

Screenshot_1.webp
 
Use the conditional in the template around the code that calls banner-picker.js, e.g.

Code:
<xen:if is="@bannerPicker">
    <xen:require js="path/to/banner-picker.js" />
</xen:if>
 
I've another question. Everything works now, but how would it be possible to make this compatible?

Screenshot_2.webp

Screenshot_3.webp

The style property does not work if it is placed inside the external js file, so how can I make it compatible? It works if it is placed in the template of the style only.
 
Back
Top Bottom