Get Smarty

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:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

Passare una variabile titolo ad un template di intestazione

Quando la maggior parte dei template usa gli stessi intestazione e pié di pagina, è abbastanza comune creare dei template a parte per questi ultimi e poi includerli negli altri. Ma cosa succede se l'intestazione ha bisogno di avere un titolo diverso a seconda della pagina in cui ci troviamo? Potete passare il titolo all'intestazione nel momento dell'inclusione.

Example 18.3. Passare la variabile titolo al template dell'intestazione


mainpage.tpl
------------

{include file="header.tpl" title="Main Page"}
{* qui va il corpo del template *}
{include file="footer.tpl"}


archives.tpl
------------

{config_load file="archive_page.conf"}
{include file="header.tpl" title=#archivePageTitle#}
{* template body goes here *}
{include file="footer.tpl"}


header.tpl
----------
<HTML>
<HEAD>
<TITLE>{$title|default:"BC News"}</TITLE>
</HEAD>
<BODY>


footer.tpl
----------
</BODY>
</HTML>

    

Quando viene disegnata la pagina principale, il titolo "Main Page" viene passato a header.tpl, e quindi sarà usato come titolo. Quando viene disegnata la pagina degli archivi, il titolo sarà "Archives". Notate che nell'esempio degli archivi abbiamo usato una variabile del file archives_page.conf invece che una definita nel codice. Notate anche che se la variabile $title non è impostata viene stampato "BC News", attraverso il modificatore di variabile default.

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 5 plus 2? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk