Not a bug Templates variables & require do not work when the dependence is too much

rugk

Active member
So let's say I have a template template_base and a template_module1 and template_nice_input_box.

template_base
Code:
<xen:include template="threemagw_auto_trigger" var1="supi" />

template_module1
Code:
Something with {var1}.
<xen:require js="js/MyAddon/ThisIsAnIsland.js" /> <!-- This is not embedded! -->

<xen:include template="template_nice_input_box" inputId="myCoolInput" />

template_nice_input_box
Code:
This thing required some JS

<input id="{$inputId}" …></input> <!-- This does not work! -->

As you can see, they all depend on the template_nice_input_box in the end.
So the variable in template_module1 works. However some other things go wrong.

Firstly, the JS is not embedded. It only seems to be embedded if it is actually put into the first template and it cannot be included in a "sub-template".
Strangely, I could only reproduce this for admin templates.

Secondly the variable $inputId, which is passed to template_nice_input_box is gone. Actually it cannot be used in template_nice_input_box at all, although passing of variables works when done in the first template.

This is of course a made-up untested example, but I discovered the issues when trying to do these things.

XenForo v1.5.7 (I checked the changelog of newer versions and I did not saw that this issue would be fixed)
 
I have never come across this issue. Possibly because when I pass data from a primary template to a secondary template I do it this way (?):

HTML:
<xen:include template="rpmodule_scoundrel_interact">
        <xen:set var="$var1">{$scoundrel.var1}</xen:set>
        <xen:set var="$var2">{$scoudrel.var2}</xen:set>
</xen:include>

I also let the primary template decide if additional js/css should be loaded or not (if the secondary template is called then load the required js/css, if it is not called then don't).
 
Nice this works indeed.
Also - for some reason - when I use this syntax also the js/css requirements are done properly.
 
Includes don't pass variables from attributes like that -- you either "set" or "map" them via child tags. As such, there's no expectation that $inputId would be valid. If $var1 was valid, it was presumably valid because included templates receive the containing template's scope/variables.

I see no reason for any of this to affect the use of <xen:require> so I have to guess this is related to the previous issue. If you can reproduce this with the values specifically set, then an add-on that demonstrates the issue as a reduced test case would be helpful. I'm going to move this to resolved bugs, but if you provide a test case, then we can look into it further.
 
Back
Top Bottom