Jump to content

Smarty: Include header file with business logic?


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...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.