Welcome Guest, Not a member yet? Register   Sign In
Template Parser Question
#1

[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?
#2

[eluser]mbent[/eluser]
Anyone?
#3

[eluser]sophistry[/eluser]
i think you want http://us.php.net/manual/en/function.extract.php
#4

[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.
#5

[eluser]sophistry[/eluser]
use it in the controller.
#6

[eluser]mbent[/eluser]
I don't quite understand how you mean.

Could you please explain?

:-S

Sorry
#7

[eluser]sophistry[/eluser]
post your controller code where the $data is assigned and i'll try to help.
#8

[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.
#9

[eluser]featureBlend[/eluser]
You might want to check out Colin's Template contribution HERE.

It's this point that i liked the most:

Quote:You prefer having one "master template" that can be changed for any controller in order to meet unique application design needs.
#10

[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




Theme © iAndrew 2016 - Forum software by © MyBB