?
Dokumen ini menggunakan Manual laman web PHP Cina Lepaskan
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.
當你的大多數(shù)模板文件用到了一些相同的頭模板文件和腳模板文件,通常是把這些模板分開并且包含他們。但是如果頭模板需要什么來使得顯示一些不同的標題,取決于你用到的那些頁面?你可以傳遞這些標題給頭模板---當它們被包含的時候。
Example 18-3. Passing the title variable to the header template 例 18-3.傳遞變量標題給頭模板
|
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.
當這個主頁[main page]被瀏覽的時候,‘Main Page'這個標題就會傳遞給頭模板文件[header.tpl],并且結(jié)果會被用成為標題。當這個檔案頁[archives page]被瀏覽的時候,文件標題將會是‘Archives'。注意在這個檔案頁例子中,我們用了一個來自這個文件[archives_page.conf]的變量來代替一個硬性的代碼變量。當然,要是變量[$title]沒有初始化,我們會發(fā)現(xiàn)‘BC News'被輸出----用那種使用默認值的變量的方法。