Template Parser Question |
[eluser]mbent[/eluser]
I have a question about the template parser. I have a lot of variables that need to be replaced on a page and to tidy things up I want to group them. So inside the $data array that gets parsed to the template parser, I have a key called office: $data['office'] and inside that I have an array holding 'office_phone', 'office_fax' etc etc. But I don't want to put {office} {/office} in my template because it is NOT something that repeats. There is only one set of this information. I just merely want to encapsulate this information so it is easier to access and customise. I was thinking maybe it should be accessible by doing a {<array>/<arrayitem>}. Otherwise I am going to have a billion things in my data array For example, {office/office_phone} would go into the office array and pull out office_phone. Currently I have to go: {office} <div class="address">{office_address}</div> <div class="website"><a href="{website}">Visit our website</a></div> <div class="phone">Ph: {office_phone}</div> <div class="fax">Fax: {office_fax}</div> {/office} I currently think this is the only thing lacking in the template parser class. What do you think? Or is there something I'm completely missing?
[eluser]sophistry[/eluser]
i think you want http://us.php.net/manual/en/function.extract.php
[eluser]mbent[/eluser]
how will i use this in my template? Since anyone can upload their own template, I would rather not allow them to use PHP code in the template. Its for a newsletter system I am creating. Different offices can have their own newsletter look.
[eluser]mbent[/eluser]
I don't quite understand how you mean. Could you please explain? :-S Sorry
[eluser]sophistry[/eluser]
post your controller code where the $data is assigned and i'll try to help.
[eluser]xwero[/eluser]
If you only have one office_address, website, ... you better put them in different variables instead of wrapping them in a one item array.
[eluser]Sen Hu[/eluser]
I use biterscripting on the side a lot for template parsing. I store the template in a form like the following. var str template set $template = "<office>123 Main Building</office><telephone>111-222-3333</telephone> ... " Then for each word, check if it is in $template, then use the sal command to replace the tag with the corresponding value in $template. Sen |
Welcome Guest, Not a member yet? Register Sign In |