Technically speaking they're not really "XenForo arrays" but it was just a simple way of saying "How to handle arrays in XenForo so that you can use them in your templates" which as you can probably tell is a little on the long side.
Right then, if you've read my topic which explains the function responseView (It can be found here if you haven't) then you'll know how to hand arrays of information over to XenForo's templates. This can be really handy but how do you use the arrays of information you give to the template?
Like this:
This little code snippet has a lot of new things in that you probably haven't seen before so I'll explain each part.
<xen:foreach> - This is part XenForo's XSLT (http://en.wikipedia.org/wiki/XSLT). Simply, it gives you the ability to use a foreach function in your template, which is useful for cycling through arrays of information. The "loop" attribute is the array of information you want to cycle through and "value" is the attribute that says you want the value of it to be the name used for it in each cycle. This is basically a similar thing to PHP's foreach construct:
This would be the equivalent of the XSLT code above.
{$rand.info} / {$rand.0} - This is how you would refer to a variable in an array. Think of PHP once again, if you did:
It would fail, in some way, or at the very least not display how you would want it to. So you encase $rand['info'] with braces ( {} ) so that it would like this:
Which would cause it to display that perfectly fine. The same goes for when using arrays in XenForo's templates. There is only two differences between PHP's use of arrays and XenForo's. In PHP you use brackets around the "key" to value in the array, whereas in XenForo you need only put a fullstop after giving the variable name of the array (i.e. $rand) and then putting the key after it.
The other one is that in PHP you need to not only have brackets around string "keys" but you also need to have the string placed inside either single or double quotation marks, whereas in XenForo you can do exactly the same for both string "keys" and numerical "keys".
After explaining all this it'd be good to have an example to give you, so here it is:
This is what you do with your responseView
Then you can use it in your template like this:
Which will end up returning this:
So there you have it guys! That's how you use arrays in templates on XenForo. Hope you found this useful.
As always if you have any questions about this, let me know and I'll try to give you and answer to the best of my knowledge.
Right then, if you've read my topic which explains the function responseView (It can be found here if you haven't) then you'll know how to hand arrays of information over to XenForo's templates. This can be really handy but how do you use the arrays of information you give to the template?
Like this:
Code:
<xen:foreach loop="$info" value="$rand">
{$rand.info} - {$rand.0}<br />
</xen:foreach>
<xen:foreach> - This is part XenForo's XSLT (http://en.wikipedia.org/wiki/XSLT). Simply, it gives you the ability to use a foreach function in your template, which is useful for cycling through arrays of information. The "loop" attribute is the array of information you want to cycle through and "value" is the attribute that says you want the value of it to be the name used for it in each cycle. This is basically a similar thing to PHP's foreach construct:
PHP:
foreach ( $info as $rand ) {
echo "{$rand['info']} - {$rand[0]}<br />";
}
{$rand.info} / {$rand.0} - This is how you would refer to a variable in an array. Think of PHP once again, if you did:
PHP:
echo "$rand['info']";
PHP:
echo "{$rand['info']}";
The other one is that in PHP you need to not only have brackets around string "keys" but you also need to have the string placed inside either single or double quotation marks, whereas in XenForo you can do exactly the same for both string "keys" and numerical "keys".
After explaining all this it'd be good to have an example to give you, so here it is:
This is what you do with your responseView
PHP:
$this->responseView('Test_ViewPublic_Index','test-template',array(
'test' => array(
array (
'This is a string with a numerical key',
'info' => 6 // This is a numerical value with a string key
),
array (
'This is a string with a numerical key',
'info' => 7 // This is a numerical value with a string key
)
)
);
Code:
<xen:foreach loop="$test" value="$info">
{$rand.0} - {$rand.info}<br />
</xen:foreach>
HTML:
This is a string with a numerical key - 6<br />
This is a string with a numerical key - 7<br />
So there you have it guys! That's how you use arrays in templates on XenForo. Hope you found this useful.
As always if you have any questions about this, let me know and I'll try to give you and answer to the best of my knowledge.