1. 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?

Discussion in 'Styling and Customization Questions' started by Dylan V, Jul 1, 2015.

  1. Dylan V

    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?
     
  2. Mike

    Mike XenForo Developer Staff Member

    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.
     
  3. Dylan V

    Dylan V Well-Known Member

    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
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    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 likes this.
  5. Brogan

    Brogan XenForo Moderator Staff Member

    Put the conditional statement in the template and call the js file within it.
     
    Dylan V likes this.
  6. Dylan V

    Dylan V Well-Known Member

    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.
     
  7. cclaerhout

    cclaerhout Well-Known Member

  8. Dylan V

    Dylan V Well-Known Member

    Thanks. I can't apply this, because I did not need to add a class directly. It is added when I click on the element, so I don't know how I can do.
     

Share This Page