[phplib] Changes to template.inc From: Chris Padfield (contact <email protected>)
Date: 04/26/01

I am trying to ammend the template section and am getting stuck. Looking for
any help.

What i want to do, is have a function that accepts an array of templates,
collects them from a database (i am using a database as opposed to .ihtml
files) but then also does the set_var function.

The way i would then use them is at the top of a php page just send of an
array of templates to a function and by doing that i can simply parse the
template whenever i want later on during the script.

The first bit i have done with the following functions:

function template_parse($array) {
foreach($array as $key => $val) {
$build .= " \"$key\" => $val,";
}
$build = substr($build,0,-1);
return $build;
}

function template_get($template) {
global $db;
$query = "SELECT * from email WHERE name in ($template)";
$db->query($query);
while($db->next_record()) {
      $tmp[$db->f(name)] = $db->f(email);
  }
    return $tmp;
     }

and I call it like:

$templatestoget = array("user", "admin");
$templates = template_get(array_sort($templatestoget));

but then I have to also do:

$t->set_var(array(
    "user" => $templates["user"],
    "admin" => $templates["admin"],
    ));

it is this bit that i would like to be part of 1 big function so at the top
of the page all I have is:

$templatestoget = array("user", "admin");
$templates = template_get(array_sort($templatestoget));

and everything is done. To use any of the templates specified inside the
array at the top all i would have to do is:

$t->pparse("MyOutput","nameoftemplate");

Also, if it is possible to combine the template_get and array_sort functions
that would be good, i failed to get it to work.

Has anyone done anything like this? if so i would be most grateful for any
sample code.

Thank you

Chris Padfield
http://www.ascifi.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>