Zh-tw/條件式標籤
From Textbook
Contents |
概述
條件式標籤允許在同一個頁面樣板或模型中依狀況的不同而顯示不一樣的內容。條件式標籤裡的代碼只會在條件符合的情況下執行。某些條件式標籤還具有 "else" 的功能,亦即當條件不符合時執行代碼。
如果閱讀完上面的說明還是無法完全理解,這些示範或許會有幫助:
單篇文章與文章列表顯示不同的導覽連結
<txp:article /> <txp:if_individual_article> <p><txp:link_to_prev>Previous article</txp:link_to_prev></p> </txp:if_individual_article> <txp:if_article_list> <p><txp:older>Older articles</txp:older></p> </txp:if_article_list>
為作者指定文章模型
<txp:if_article_author name="the-wizard"> <txp:article form="wizard-form" /> <txp:else /> <txp:article /> </txp:if_article_author>
巢狀結構
條件式標籤可以為巢狀結構,除非你在巢狀條件式標籤裡使用了重複的狀況描述。
例如這段代碼能正常執行:
<txp:if_section> I'm looking at a particular section. <txp:if_category name="oranges"> I'm also looking at the category named "oranges". </txp:if_category> </txp:if_section>
<txp:if_custom_field name="apples"> apples! </txp:if_custom_field> <txp:if_custom_field name="oranges"> oranges! </txp:if_custom_field>
但這段代碼無法執行:
<txp:if_custom_field name="apples">
apples!
<txp:else />
<txp:if_custom_field name="oranges">
oranges!
</txp:if_custom_field>
</txp:if_custom_field>
文章條件式標籤
- <txp:if_article_list> ... </txp:if_article_list>
- <txp:if_individual_article> ... </txp:if_individual_article>
- <txp:if_first_article> ... </txp:if_first_article>
- <txp:if_last_article> ... </txp:if_last_article>
- <txp:if_different> ... </txp:if_different>
- <txp:if_article_section> ... </txp:if_article_section>
- <txp:if_article_category> ... </txp:if_article_category>
- <txp:if_section> ... </txp:if_section>
- <txp:if_category> ... </txp:if_category>
- <txp:if_excerpt> ... </txp:if_excerpt>
- <txp:if_custom_field> ... </txp:if_custom_field>
迴響條件式標籤
- <txp:if_comments > ... </txp:if_comments>
- <txp:if_comments_allowed > ... </txp:if_comments_allowed>
- <txp:if_comments_disallowed > ... </txp:if_comments_disallowed>
搜尋條件式標籤
- <txp:if_search> ... <txp:else /> ... </txp:if_search> 雙重的條件式標籤允許你讓搜尋結果與主要頁面共同使用同一個樣版




