Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Largest classified with thousands of ads at Shoppok

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy wedding dresses on SiteSteer.com - Best Online Wedding Dress Store

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Passing variable title to header template

When the majority of your templates use the same headers and footers, it is common to split those out into their own templates and {include} them. But what if the header needs to have a different title, depending on what page you are coming from? You can pass the title to the header as an attribute when it is included.

Example 21.3. Passing the title variable to the header template

mainpage.tpl - When the main page is drawn, the title of Main Page is passed to the header.tpl, and will subsequently be used as the title.


{include file='header.tpl' title='Main Page'}
{* template body goes here *}
{include file='footer.tpl'}

    

archives.tpl - When the archives page is drawn, the title will be Archives. Notice in the archive example, we are using a variable from the archives_page.conf file instead of a hard coded variable.


{config_load file='archive_page.conf'}

{include file='header.tpl' title=#archivePageTitle#}
{* template body goes here *}
{include file='footer.tpl'}

    

header.tpl - Notice that Smarty News is printed if the $title variable is not set, using the default variable modifier.


<html>
<head>
<title>{$title|default:'Smarty News'}</title>
</head>
<body>

    

footer.tpl


</body>
</html>

    

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 17 plus 0? (Are you human?)

Sponsors [info]

UK Web Hosting @webhost.uk.net
Best Web Hosting @rshosting.com
Web Hosting UK @webhostinguk.com
Unlimited Web Hosting @infrenion.com
App Entwicklung @morphodo.com
Buy from China @dhgate.com
First Click Internet Marketing @fcinternetmarketing.com