• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

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

Dylan V

Well-known member
#1
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?
 

Mike

XenForo developer
Staff member
#2
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.
 

Dylan V

Well-known member
#3
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.png
 

Chris D

XenForo developer
Staff member
#4
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>
 

Dylan V

Well-known member
#6
I've another question. Everything works now, but how would it be possible to make this compatible?

Screenshot_2.png

Screenshot_3.png

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.