XF 2.0 Type and ID parameters to <xf:js>? Alternatives?

DragonByte Tech

Well-known member
I'm using jQuery Templates to render data sets returned by one of our mods. I attempted to define one of the templates in this way: <xf:js type="text/x-jquery-tmpl" id="shoutboxShoutTypeMe"> but that produced a syntax error.

I require the type tag in order for jQuery Templates to recognise the script tag, and I need the ID so that my code knows which of the 5 different templates to render.

I have the following set of requirements:
  • If the widget is not deployed on any given page, this JS should not be added to that page
  • The JS should be in the bottom, same way all the other JS from <xf:js> is
  • The rendered <script> tag should be <script type="text/x-jquery-tmpl" id="shoutboxShoutTypeMe">
What are my options here? Alternatively, would it be a lot of work to get the "type" and "id" attributes supported in <xf:js>?

Thanks!


Fillip
 
Your tag is quite definitively not JS related, despite the fact you're using a <script> tag. Indeed, that's just a hack (though we do the same with Mustache templates).

You would need to just use the <script> tag directly, but there isn't any system to insert arbitrary text at the end of the page. We do things like this with the templates inserted where they're called. You can find examples with the editors and the attachment system.
 
I've had a quick search through the templates and Google, and it seems like Mustache doesn't have logic checks which means I can't use them for this purpose.

I guess the best option would be to add a template modification that adds my jQT templates to the footer of every page. It works out to be less than 100 lines in total, and what with it being in the footer, it shouldn't have any render blocking effects.

Thanks for the reply :)


Fillip
 
Top Bottom