Jump to content

Smarty: Include header file with business logic?


rlelek

Recommended Posts

Hello everyone!

 

I was just curious how I would go about implementing a dynamic header/footer in Smarty/PHP5

I cannot use the smarty 'include file="header.tpl"' function because I need logic applied to the template. Since the whole point of smarty is to separate these, i really would like to figure this out... and i don't want to use

 tags in the template.

Would I have to access the necessary header/footer data in the business layer for the specific page and then, in the template layer, include those two templates (header/footer) and pass them an array of data to use?

I would rather not write "<?php include_once('header.php') ?>" in every script just to get the header logic.

Also, even if I did do it by this method, what happens when there are multiple smarty objects? I know each object is separate, but what happens when there is more than one "display" method envoked?

example ...

[code]

// header.php
<?php 
$header = new Smarty;
// do all the array assignments
[b]$header->display('header.tpl');[/b]
?>

// footer.php
<?php 
$footer = new Smarty;
// do all the array assignments
[b]$footer->display('footer.tpl');[/b]
?>


// index.php

<?php include_once('header.php'); ?>

<?php 
$index = new Smarty;
// do all the array assignments
[b]$index->display('index.tpl');[/b]
?>

<?php include_once('footer.php'); ?>

 

How would those triple display statements work?

 

Sorry for all these questions, but i've just been so confused :D

 

Thanks in advance...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.