Author Topic: Multiple template files  (Read 876 times)

0 Members and 1 Guest are viewing this topic.

RNilsson

  • Guest
Multiple template files
on: Fri, 08. November 2002 - 19:03:28
If i understand and read the docs and vlibTemplate code correctly, i just do:
$tmpl_header->newTemplate('./templates/header.html');
$tmpl_newsheader->newTemplate('./templates/news.html');
$tmpl_newscontent->newTemplate('./templates/newscontent.html');
$tmpl_menu->newTemplate('./templates/menu.html');
$tmpl_footer->newTemplate('./templates/footer.html');
And i put these in appropreate places in my index.php-file correct?

*Just wanted to streight that out before i start redoing my site =)

releasedj

  • Guest
Multiple template files
Reply #1 on: Fri, 08. November 2002 - 22:56:24
If you have a different variable with each template, you would have to instantiate the class for each one, i.e.:

$tmpl_header = new vlibTemplate('./templates/header.html');
$tmpl_newsheader = new vlibTemplate('./templates/news.html');

...etc.

Alternatively, you can instantiate the class into 1 variable, and have a seperate include file for each template. For example, I have a config file for each page on the site, which defines which php files to include, i.e. header.php, content.php, footer.php ...etc.
The config file will instantiate the class into $tmpl and then each included file (header.php ..etc.) starts with $tmpl->newTemplate(...blah..); and ends with $tmpl->pparse();.

If this is unclear, here's a small sample:

Code: [Select]

common.php

-----------------

?php

  include '../vLIB/vlibTemplate.php';

  $tmpl = new vlibTemplate;



  // include header

  include './includes/header.php';



  // include content

  include './includes/content.php';



  // include footer

  include './includes/footer.php';

?



and then in one of the include files you would do:

Code: [Select]

content.php

-----------------

?php

  $tmpl-newTemplate'../templates/content.html';

  

  $tmpl-setVar'some_var', 'some value';



  $tmpl-pparse;

?



You see. You can do this to build up your pages.

I hope this helps.. if not then let me know.

Regards,

Kelvin

RNilsson

  • Guest
Multiple template files
Reply #2 on: Sat, 09. November 2002 - 03:31:50
Yup, that helped alot, now i just can't decide on which method to use =D

Both styles have it's advantages and disadvantages...

Less files with the first version, but larger and perhaps clutter-code in the few files.
One parse the templates direct into the current file...


The second style gives more files, but able to sort them into categories depending on their use...
I have include-files that parse the templates...

I wonder which style is most favorable for use with easySkinning/Templating...


Anyhow, i'm gonna do some testing with both styles, but my money is on the first style...

What are the impacts of making for instance 5 '$teml_<name> = new vlibTemplate(..blah);'

vs

$tmpl = new vlibTemplate();

and then just newTemplate(template_<name>) 5 times.

Any ideas in that area?

releasedj

  • Guest
Multiple template files
Reply #3 on: Sat, 09. November 2002 - 13:54:45
If you do with the 1st style ('$tmpl_<name> = new vlibTemplate(..blah);') then there will be a slightly bigger overhead because you have 5 different objects that need to be created... but then you have the freedom of where to set variables and where to parse the templates.. however this can lead to messy code.

The second method will be slightly faster as it uses just 1 vlibTemplate object, but then you loose some freedom in how you program.

Personally, I think that the 2nd method is best as it also helps keep your code organised.


Regards,

Kelvin