Template Tricks
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 ->Table of contents
- Adding a print button only if current page is a wiki page
- Adding a "Hello John" indication
- Adding content only for a group
- Adding content only for a permission
- Adding content only for a preference
- Display content conditional to current language
- How to know where something is in a template?
- How to show content just when in certain pages
- Debug
- Categories used in templates
- Section
- Perspective
- Related
Adding a print button only if current page is a wiki page
{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}Adding a "Hello John" indication
{if $user}
Hello {$user}
{/if}Adding content only for a group
In content
In a template
{if $group eq "Admins"}
You are a member of the group {$group}
{/if}Adding content only for a permission
Adding content only for a preference
{if $prefs.feature_wiki eq "y"}
The Wiki feature is on
{/if}Display content conditional to current language
{if $prefs.language eq "fr"}
<a href="accueil">
{elseif $prefs.language eq "es"}
<a href="inicio">
{else}
<a href="tiki-index.php">
{/if}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.tplFor 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
{if $mid eq "tiki-searchresults.tpl"}
bla bla
{/if}Debug
Put in a template or in Site Identity to have a popup with information on all the variables, at each page refresh.
{debug}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
{if $section eq "blogs"}
text shown just when in one of the blog pages
{/if}Perspective
The current perspective ID is not available to the templates. However, you can simply use the value of something that was overriden in this template. This could be in one of the Site identity fields.To change the menu depending on the Site title
{if $prefs.sitetitle eq "Workspace Sales"}
{phplayers id=45 type=horiz css=y}
{else}
{phplayers id=47 type=horiz css=y}
{/if}Related
Templates Best PracticesAdvanced Wiki Syntax usage examples
Sidebar
Last changes
Site Config
-
Configurable header buttons in XtratoVeil layout
Sat 17 of Oct., 2009 12:54 GMT
-
Infinite Carousel problem and workaround
Mon 21 of Sep., 2009 05:55 GMT
-
Various preference changes
Tue 15 of Sep., 2009 07:02 GMT
-
Some changes now that we have Tiki 3 here
Fri 28 of Aug., 2009 16:45 GMT
-
Site updated to Tiki 3
Thu 27 of Aug., 2009 09:52 GMT
-
Turning some stuff on & off
Sat 25 of Oct., 2008 11:30 GMT
-
Menu demos updated
Sat 25 of Oct., 2008 09:46 GMT
-
Site upgraded to Tiki 2.1
Thu 16 of Oct., 2008 12:45 GMT
Sidebar
Theme: Strasa
To register
To have an account at this site, please register at Tikiwiki.org, and then use that user name and password to log in here.
This site gets user information from Tikiwiki.org with the ))InterTiki(( feature.
This site gets user information from Tikiwiki.org with the ))InterTiki(( feature.
Shoutbox
chibaguy, 00:57 GMT, Sun 14 of Mar., 2010:
Site updated to Tiki5 alpha.
chibaguy, 06:51 GMT, Sun 20 of Dec., 2009:
Site updated to Tiki 4.1.
chibaguy, 01:45 GMT, Mon 23 of Nov., 2009:
Thanks, Xavi.
xavi, 17:54 GMT, Sun 22 of Nov., 2009:
Gary, check that perms are all right for registered (I saw zero perms an hour ago). See message on devel list
chibaguy, 04:54 GMT, Mon 16 of Nov., 2009:
Updated to Tiki 4.0!
