PHPマニュアル/PEARマニュアル | ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot

Passing variable title to header template | JavaScript入門&応用&リファレンスなら「JavaScriptist」

  

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 when it is included.

Example 18-3. Passing the title variable to the header template


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

{include file="header.tpl" title="Main Page"}
{* template body goes here *}
{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>

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. 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. Also notice that "BC News" is printed if the $title variable is not set, using the default variable modifier.

忘却曲線を使ってこの知識を確実に記憶に残す

フォーラムで「Passing variable title to header template」について話す
各種マニュアル: PHPマニュアル | PEARマニュアル | Smarty(英語)マニュアル | PHP-GTKマニュアル | Passing variable title to header template」をGoogle検索
copyright © 1997-2024 PHP ドキュメント作成グループ(ライセンス). provided by php spot. マニュアル: