PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
{section name=id loop=$T_array}
link: {$T_array[id].$link} {* It doesn't work *} <br />
link: {$T_array[id].link} {* It doesn't work *} <br />
link: {$T_array[id][$link]} {* It doesn't work *} <br />
link: {$T_array[id][link]} {* It doesn't work *} <br />
{/section}
I think one of the best ways to pass data to the template is through a multidim array, but I'm a little bit dissapointed how different is looping arrays in TL from a PHP point of view
Why are you using the {section} tag? I only added support for it to be compatible with Smarty. If this is your own code you should use something else like the {foreach} tag. The {section} tag is very, very slow and quite frankly is about as stupid a function as could have been created for templating.
The above should work just fine for you. I gave an example of also displaying data four elements deep in your array. This is a Smarty variable convention and I copied it with Template Lite. When you are working with multi-dimensional arrays in a template you shouldn't use the PHP brackets [] to separate the elements after the first element. Smarty uses brackets [] for reserved variable access. You should always use the period (.) as a delimiter between each array element.
Do I personally like that?
No.
But that is how Smarty was written and I am trying to stay compatible with Template Lite. Personally I would rather use the PHP syntax for multi-dimensional arrays.
julian_lp wrote:Is there any TL gurú in this forum?
I believe AKA Panama Jack wrote Template Lite, haven't seen him post in a while though.
Staying on topic, I can't help you because I've never used TL. Sorry.
I rarely post. Usually when I can help on something but not always. I am not one of those people who feel they have to post on every subject on a forum.
I just switched to a plain PHP Template, to not to have this kind of problems.
In the near future, I'll take a look again to TL, just to see if I can adapt it to my needs
It sounds like you have OTHER problems and they are not related to Template Lite.
I took the array you posted above and used the {foreach} code I posted with the lastest version of Template Lite on Sourceforge and it worked like a charm.
AKA Panama Jack wrote:It sounds like you have OTHER problems and they are not related to Template Lite.
I took the array you posted above and used the {foreach} code I posted with the lastest version of Template Lite on Sourceforge and it worked like a charm.
About the only way it wouldn't display the above is if the array you posted is NOT the actual array being sent to the template.
Please excuse me, I should've written it, but you're absolutely right. I wasn't passing this array, you know, those kind of silly mistakes that could drive you to insanity
cause I dont know previously whether there will be 0, 1, 2 or more elements, and I have absoutely no idea if it is possible do a nested foreach in this situation
Once again, excuse me for not telling you that I was wrong with the original array.
The thing you have to remember with Smarty syntax is you can use brackets [] around the first element but every element after that you have to use periods. Like I said before damned silly but that is how they designed Smarty and I have to copy that format to stay compatible.