<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                <table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><th colspan="3" align="center">Smarty - the compiling PHP template engine</th></tr><tr><td width="25%" align="left" valign="bottom"><a href="advanced.features.changing.settings.by.tem.html">Prev</a></td><td width="50%" align="center" valign="bottom">Chapter 15. Advanced Features 高級特性</td><td width="25%" align="right" valign="bottom"> <a href="advanced.features.streams.html">Next</a></td></tr></table> # [Template Inheritance]()[模板繼承] Inheritance brings the concept of Object Oriented Programming to templates, allowing you to define one (or more) base templates that can be extended by child templates. Extending means that the child template can override all or some of the parent named block areas. The inheritance tree can be as big as you want (meaning you can extend a file that extends another one that extends another one and so on..), but be aware that all files have to be checked for modifications at runtime so the more inheritance the more overhead you add. The child templates can not define any content besides what's inside {block} tags they override, anything outside of {block} tags will be removed. The content of {block} tags from child and parent templates can be merged by the append or prepend {block} tag option flags and {$smarty.block.parent} or {$smarty.block.child} placeholders. Template inheritance is a compile time process which does create a single compiled template file. Compared to corresponding solutions based on subtemplates included with the {include} tag it does have much better performance when redering. The child template does extend its parent defined with the {extends} tag, which must be the first line in the child template. Instead of using the {extends} tags in the template files you can define the whole template inheritance tree in the PHP script when you are calling fetch() or display() with the extends: template resource type. The later provides even more flexibillity. 繼承帶來了模板面向對象概念(oop),它允許你定義一個或多個基模板供子模板繼承。繼承意味著子模板可覆蓋所有或部份父模板中命名相同的塊區域。 繼承樹大小沒有規定,只要你愿意你想搞多大都可以(意為你繼承的文件上面有個父文件,父文件上面可以有個爺文件,爺文件上面有個曾祖父文件...生生不息無窮盡),但需要注意所有文件都必須在運行時檢查修改設置,更多的繼承意味著更大的開銷。 子模板不能定義任何內容,除了需要覆蓋父模板的[{block}](#)標簽塊,所有在{block}標簽外的內容將被自動移除。 子模板和父模板的{block}標簽內容可以合并,方法一:用***append***添加或***prepend***追加{block}標簽選項標記;方法二:使用[{$smarty.block.parent}](#)或[{$smarty.block.child}](#)占位符。 模板繼承是一種編譯時進程,其將建立一個獨立的編譯模板文件。與對應的基于載入[{include}](#)子模板解決方案相比,當解釋模板時,前者有更好的性能。 子模板通過[{extends}](#)標簽定義繼承父模板,該定義應寫在子模板的第一行。與在模板文件中使用{extends}標簽不同的是,你可以使用“*extends:*模板資源類型”(見[extends:resource](#)),調用[fetch()](#)或[display()](#)函數在php腳本中定義整個模板繼承樹。后一個方法提供更大的彈性。 <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/> If you have a subtemplate which is included with {include} and it does contain {block} areas it does work only if the {include} itself is called from within a surrounding {block}.In the final parent template you may need a dummy {block} for it.<br/> 如果有一個通過{include}標簽載入的子模板,而且它包含{block}區域,那么該{block}區域只能工作在調用{include}標簽的{bolck}塊的內部。在最終的模板中,你應該再為該{include}子模板添加另一個形式上的{block}標簽。</td> </tr></table> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td> <div class="EXAMPLE"> <strong><a name="AEN4156" id="AEN4156"> </a>Example 15.6. Template inheritance example<br/> 例15-6.模板繼承示例</strong> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><p> layout.tpl (parent) 父模板 <br/> &lt;html&gt;<br/> &lt;head&gt;<br/> &lt;title&gt;{block name=title}Default Page Title{/block}&lt;/title&gt;<br/> &lt;span style="color: blue"&gt;{block name=head}{/block}&lt;/span&gt;<br/> &lt;/head&gt;<br/> &lt;body&gt;<br/> {block name=body}{/block}<br/> &lt;/body&gt;<br/> &lt;/html&gt;</p> <p> <br/> myproject.tpl (child) 子模板 <br/> {extends file=layout.tpl}<br/> {block name=head}<br/> &lt;link href="/css/mypage.css" rel="stylesheet" type="text/css"/&gt;<br/> &lt;script src="/js/mypage.js"&gt;&lt;/script&gt;<br/> {/block}</p> <p> <br/> myproject.tpl (grandchild) 孫子模板(譯注:應為mypage.tpl吧?!) <br/> {extends file=project.tpl}<br/> {block name=title}My Page Title{/block}<br/> {block name=head}<br/> &lt;link href="/css/mypage.css" rel="stylesheet" type="text/css"/&gt;<br/> &lt;script src="/js/mypage.js"&gt;&lt;/script&gt;<br/> {/block}<br/> {block name=body}My HTML Page Body goes here{/block}</p> <p> <br/> To render the above use 上述使用如下渲染 <br/> $smarty-&gt;display('mypage.tpl');</p> <p><br/> The resulting output is 輸出結果<br/> &lt;html&gt;<br/> &lt;head&gt;<br/> &lt;title&gt;My Page Title&lt;/title&gt;<br/> &lt;link href="/css/mypage.css" rel="stylesheet" type="text/css"/&gt;<br/> &lt;script src="/js/mypage.js"&gt;&lt;/script&gt;<br/> &lt;/head&gt;<br/> &lt;body&gt;<br/></p> <p>My HTML Page Body goes here<br/> &lt;/body&gt;<br/> &lt;/html&gt;</p></td></tr></table><p><strong>Example 15.7. Template inheritance by template resource extends:<br/>例15-7.通過</strong><strong>模板資源繼承的模板繼承</strong><br/>Instead of using {extends} tags in the template files you can define the inheritance tree in your PHP script by using the extends: resource type.<br/>The code below will return same result as the example above.<br/> 不在模板文件中使用{extends}標簽,取而代之的是用“<em><strong>extends:</strong></em>模板資源類型”,在php腳本中定義整個模板繼承樹。下面的代碼會返回與上例同樣的結果。</p> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><br/> &lt;?php<br/> $smarty-&gt;display('extends:layout.tpl|myproject.tpl|mypage.tpl'); <br/> ?&gt;</td> </tr></table><p> 參見<a href="language.function.block.html">{block}</a>、<a href="language.function.extends.html">{extends}</a>和<a href="template.resources.html#tidbps">extends: 資源</a>。</p> </div></td></tr></table> <table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="advanced.features.changing.settings.by.tem.html">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html">Home</a></td><td width="33%" align="right" valign="top"> <a href="advanced.features.streams.html">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Changing settings by template<br/> 通過模板更改設置</td><td width="34%" align="center" valign="top"><a href="smarty.for.programmers.html">Up</a></td><td width="33%" align="right" valign="top">Streams<br/> 數據流</td></tr></table>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看