History: Template Tricks
Source of version: 5
- «
- »
Copy to clipboard
Below, we will document some little template tricks. Typically show content depending on something. Can be done directly in templates/*.tpl files or in Admin -> Look & Feel -> {maketoc} !!Adding a print button only if current page is a wiki page {CODE()} {if $page neq ''} <a title="{tr}Print{/tr}" href="tiki-print.php?page={$page|escape:"url"}"> <img src="pics/icons/printer.png"/>{tr}Print{/tr} </a> {/if} {CODE} !!Adding a "Hello John" indication {CODE(ishtml="1")} {if $user} Hello {$user} {/if} {CODE} !!Adding content only for a group !!! In content *((doc:PluginGroup)) !!! In a template {CODE()} {if $group eq "Admins"} You are a member of the group {$group} {/if} {CODE} !!Adding content only for a permission !!Adding content only for a preference {CODE()} {if $prefs.feature_wiki eq "y"} The Wiki feature is on {/if} {CODE} !!Display content conditional to current language {CODE()} {if $prefs.language eq "fr"} <a href="accueil"> {elseif $prefs.language eq "es"} <a href="inicio"> {else} <a href="tiki-index.php"> {/if} {CODE} !! How to know where something is in a template? Admin -> Look & Feel Add HTML comment at start and end of each Smarty template (TPL) New in 3.0, turn on "log_tpl" to add comments in templates (if you click view source, you can see which tpl was used to create it !! How to show content just when in certain pages So if you want to modify tiki-searchresults.php, you find templates/tiki-searchresults.tpl !!! For the container templates/tiki.tpl is the master container. Say you want to affect the master container based on the current page, you can do {CODE()} {if $mid eq "tiki-searchresults.tpl"} bla bla {/if} {CODE} !! Debug Put in a template or in Site Identity to have a popup with information on all the variables, at each page refresh. {CODE()} {debug} {CODE} !! Categories used in templates Admin -> Category -> Categories used in templates (TPL) (categories_used_in_tpl) How to use? Something like http://doc.tikiwiki.org/Category+Admin#Using_the_current_object_categories_in_a_tpl http://dev.tikiwiki.org/Hello+World#To_do_something_specific_in_a_template_ex.:_tiki.tpl_conditional_to_the_current_item_being_in_a_category._Ex.:_different_header_picture. !!Section {CODE()} {if $section eq "blogs"} text shown just when in one of the blog pages {/if} {CODE} !! Perspective You can use Site identity !Related ((dev:Templates Best Practices))