History: Template Tricks
Preview of version: 45
Table of contents
[Show/Hide]- About
- Custom CSS and JS
- Help, I broke my theme !
- Howto
- 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 do I change the email messages?
- How to show content just when in certain pages
- How to force switch Theme for Anonymous
- Add wiki syntax in Custom code text areas of Look & Feel
- Timed content
- Dynamic content
- Add a wiki page in module
- How to Add Custom jQuery Code Using the Custom Code Textareas
- Debug
- Categories used in templates
- Section
- Perspective
- Variables
- Alternate view of wiki content
- Related
About
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.
Custom CSS and JS
Starting in Tiki5, in Admin > Look & Feel (tiki-admin.php?page=look) > Miscellaneous, there is a Custom Code section to add custom CSS and JavaScript.
Change size of subtitle
#sitesubtitle { font-size: 24px; }
Help, I broke my theme !
Apparently, a problem with my custom theme is preventing me from accessing my site normally.
Reset the theme "manually": If you can't access the admin pages to set your site's theme back to one that is known to work, you can reset the theme from the back end, so to speak.
Database method: Use phpmyadmin on your server to access your Tiki database. In the table "tiki_preferences", find the row for "site_style". Edit this row by replacing the custom theme name with a standard theme, such as thenews.css.
FTP method (easier): Using your FTP client, go to the styles directory of your Tiki installation and rename the theme currently set as the site theme, such as by changing its ".css" file extension to ".txt". Tiki will revert to the default. Log in using the default theme and fix what is wrong. Also clear the site caches.
When trying out a new theme, it is much better to use the "switch theme" module to select it. Don't make a new and untried theme the site theme without first trying it out from the switch-theme module.
I am stuck in a theme
To change themes, you can point your browser to a non faulty theme:
- Point your browser to: tiki-switch_theme.php?theme=fivealive.css
- Then, also check to Clear the cache with tiki-admin_system.php?do=all
If anything doesn't change
For some unknown reason the theme doesnt change. Look directly in the database in 'tiki_preferences'
look at:
UPDATE `tiki_preferences` SET `value` = 'fivealive.css' WHERE `tiki_preferences`.`name` = 'style';
Howto
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
{if $tiki_p_admin eq 'y'} You have full admin rights {/if}
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}{tr}Home{/tr}</a>
This is an Smarty block to display only if language matches.
It's one quick hack like PluginLang, but to use in modules and templates.
Example:
{translation lang="en"}Hello{/translation}
{translation lang="pt-br"}Olé{/translation}
If the current language is en, Hello will be displayed. If it is pt-br, Olé.
To make users switch language, you can add Module switch_lang or hard code some links such as:
{if $prefs.language eq "fr"} <a href="tiki-switch_lang.php?language=fr">-English-</a> -Français- <a href="tiki-switch_lang.php?language=es">-Español-</a> {elseif $prefs.language eq "es"} <a href="tiki-switch_lang.php?language=en">-English-</a> <a href="tiki-switch_lang.php?language=fr">-Français-</a> -Español- {else} -English- <a href="tiki-switch_lang.php?language=fr">-Français-</a> <a href="tiki-switch_lang.php?language=es">-Español-</a> {/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. Make sure to turn off once you go into production, or else your email notifications will also have a note!
How do I change the email messages?
Look in: templates/mail/
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
{if $mid eq "tiki-searchresults.tpl"} bla bla {/if}
How to force switch Theme for Anonymous
You could use the Group Theme feature but it seems broken currently in Tiki 5 so here's a workaround using Javascript code in Admin > Look & Feel > General Layout > Custom HTML <head> Content ("Registered users can switch themes" - preference name change_theme - must be enabled):
{if !$user and $prefs.style ne "jqui.css"}<script type="text/javascript"> <!-- window.location = "tiki-switch_theme.php?theme=jqui.css" //--> </script>{/if}
Add wiki syntax in Custom code text areas of Look & Feel
{wiki}{literal} ::My __wiki__ code:: {/literal}{/wiki}
Timed content
Dynamic content
Add a wiki page in module
How to Add Custom jQuery Code Using the Custom Code Textareas
Debug
Put in a template or in Look & Feel custom code to have a popup with information on all the variables, at each page refresh.
{debug}
To avoid driving your users mad 😊
{if $user eq 'admin'} {debug} {/if}
Categories used in templates
Admin -> Category -> Categories used in templates (TPL)
(categories_used_in_tpl)
How to use? Something like
http://doc.tiki.org/Category+Admin#Using_the_current_object_categories_in_a_tpl
another
To determine if an object is categorized, use:
{if !empty($objectCategoryIds)} NOT categorized {else} AM categorized {/if}
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.
{if $prefs.sitetitle eq "Workspace Sales"} {phplayers id=45 type=horiz css=y} {else} {phplayers id=47 type=horiz css=y} {/if}
Variables
Dynamic variables
Use current page name as content
How to display URL param in a page or the page name or the user name
Alternate view of wiki content
Raw
http://themes.tiki.org/tiki-index_raw.php?page=Template+Tricks
Middle only, useful to include in an iframe
http://themes.tiki.org/tiki-index_p.php?page=Template+Tricks
Fullscreen
works for all features, not just wiki pages
http://themes.tiki.org/tiki-index.php?page=Template+Tricks&fullscreen=y
related:
doc:Fullscreen
dev:Fullscreen
Slideshow
Mobile
Clearing cache
Related
Templates Best Practices
Advanced Wiki Syntax usage examples