XF 1.5 Template Syntax inside a javascript

SmauG

Member
Hello,

I'm trying to implement a dynamic chart on a custom page, but i don't really have so much clues about how to do it without the <xen:foreach>.

Basically i have an array from my model which has some integers, and i need to parse them on this way:

<xen:foreach loop="$loops" value="$loop" i="$i">
[{$i}, {$loop.a}, {$loop.b}, {$loop.c}]
</xen:foreach>

Of course on the template works great ([0,x,y,z], [1,x1, x2, x3], ...) but i need to build/read it inside the javascript script, and the template syntax doesn't work inside javascript.

Basically i need to get this inside the javascript to build the chart.
<script type="text/javascript">
data.addRows([ [0,x,y,z], [1,x1, x2, x3], ... ]);
</script>

How can i do it?
 
It's everything on the template. When i said custom page, i meant XenForo custom page (template), sorry if wasn't clear.

Basically, i need this working on the template:

<script type="text/javascript">
data.addRows([
<xen:foreach loop="$loops" value="$loop" i="$i">
[{$i}, {$loop.a}, {$loop.b}, {$loop.c}]
</xen:foreach>​
]);​
</script>

Well, it just has to be a way to parse an array from a template ( {$loops} ) inside the javascript. A for on the javascript would do the trick, but again, the array from template is the problem:

<script type="text/javascript">
for(j =0; j < {$loops}.lenght; ++){
data[j +1]=[[j], {$loops.x}[j], {$loops.y}[j]];
}
</script>

It just doesn't simply read the $loops

But the foreach and template variables can't be used inside the javascript.
 
Last edited:
Well, i just rewrote it and now it's working. Didn't really changed anything, actually using <xen:foreach> inside the <script>. So confused but ok, at least is working.
 
Back
Top Bottom