Loading...
 
Skip to main content

History: Template Tricks

Source of version: 46

Copy to clipboard
            {DIV(float=right)}{maketoc showhide=y}{DIV}
! 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
{CODE(caption="custom CSS")}
#sitesubtitle {
font-size: 24px;
}
{CODE}



! 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:
{CODE()}
UPDATE
  `tiki_preferences` 
SET
  `value` =  'fivealive.css' 
WHERE
  `tiki_preferences`.`name` =  'style';
{CODE}

! Howto
!! 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}		
...page...
!! 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
{CODE()}
{if $tiki_p_admin eq 'y'}
You have full admin rights
{/if}
{CODE}

!! 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}{tr}Home{/tr}</a>
{CODE}

This is an Smarty block to display only if language matches. 
It's one quick hack like ((doc:PluginLang)), but to use in modules and templates.

''Example'':
~np~{translation lang="en"}Hello{/translation}~/np~
~np~{translation lang="pt-br"}Olé{/translation}~/np~

If the current language is en, Hello will be displayed. If it is pt-br, Olé.

To make users switch language, you can add ((doc:Module switch_lang)) or hard code some links such as:

{CODE()}
{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}
{CODE}
...page...
!! 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
{CODE()}
 {if $mid eq "tiki-searchresults.tpl"}
  bla bla
 {/if}
{CODE}

!! 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):
{CODE()}{if !$user and $prefs.style ne "jqui.css"}<script type="text/javascript">
<!--
window.location = "tiki-switch_theme.php?theme=jqui.css"
//-->
</script>{/if}{CODE}

!! Add wiki syntax in Custom code text areas of Look & Feel
{CODE()}{wiki}{literal}

::My __wiki__ code::

{/literal}{/wiki}{CODE}

!! Add javascript tracking code
See ((doc:Piwik)) example.

!! Timed content
* ((doc:PluginContent))

!! Dynamic content
* ((doc:PluginRcontent))
* ((doc:Module random_pages))

!! Add a wiki page in module
* ((doc:Module menupage))

!! How to Add Custom jQuery Code Using the Custom Code Textareas
* ((doc:Custom Code HowTo - jQuery))

!! 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.
{CODE()}
 {debug}
{CODE}

To avoid driving your users mad :-)
{CODE()}
{if $user eq 'admin'}
 {debug}
{/if}
{CODE}
...page...

!! 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
[http://dev.tiki.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.|another]

To determine __if__ an object is categorized, use:
{CODE()}
{if !empty($objectCategoryIds)}
NOT categorized
{else}
AM categorized
{/if}
{CODE}

!! Section
{CODE()}
 {if $section eq "blogs"}
  text shown just when in one of the blog pages
 {/if}
{CODE}

!! 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.

{CODE(caption="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}
{CODE}

!! Variables

!!! Dynamic variables
((doc:Dynamic variables))

!!! Use current page name as content
((doc:Advanced Wiki Syntax usage examples|#How_to_display_URL_param_in_a_page_or_the_page_name_or_the_user_name|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:((doc:Fullscreen))
dev:((dev:Fullscreen))

!!! Slideshow
* ((doc:Slideshow))

!!! Mobile
* ((doc:Mobile))

!!! Clearing cache
* ((doc:cache))

! Related
((dev:Templates Best Practices))
((doc:Advanced Wiki Syntax usage examples))

        

History

Advanced
Information Version
Tue 16 of Mar, 2021 16:41 GMT-0000 Marc Laporte 88
Sat 14 of Nov, 2020 11:27 GMT-0000 Jonny Bradley more colours 87
Sat 14 of Nov, 2020 11:25 GMT-0000 Jonny Bradley adding code block colours 86
Sat 14 of Nov, 2020 11:22 GMT-0000 Jonny Bradley code Plugin modified by editor. 85
Sat 14 of Nov, 2020 11:21 GMT-0000 Jonny Bradley $group is only the default group (sometimes) but the in_group modifier checks all the groups a user might be in 84
Wed 04 of Sep, 2019 14:21 GMT-0000 Marc Laporte Remove ...page... that makes the page harder to use 83
Wed 04 of Sep, 2019 14:19 GMT-0000 Marc Laporte AutoTOC 82
Thu 03 of Nov, 2016 09:10 GMT-0000 Xavier de Pedro 81
Fri 26 of Jun, 2015 11:55 GMT-0000 Nelson Ko 80
Tue 12 of May, 2015 21:07 GMT-0000 Marc Laporte 79
Tue 22 of Apr, 2014 16:37 GMT-0000 Marc Laporte Linking to existing docs 78
Tue 22 of Apr, 2014 16:15 GMT-0000 Marc Laporte Code Plugin modified by editor. 77
Tue 22 of Apr, 2014 16:07 GMT-0000 Marc Laporte 76
Wed 19 of Mar, 2014 01:30 GMT-0000 Marc Laporte How do I know which template to modify to affect the look & feel of a specific URL? 75
Wed 19 of Mar, 2014 01:23 GMT-0000 Marc Laporte Cosmetic 74
Tue 02 of Apr, 2013 05:41 GMT-0000 Torsten Fabricius 73
Tue 09 of Oct, 2012 09:57 GMT-0000 Karen Stingel updated image path from 'pics/...' to 'img/...' 72
Sun 29 of Jul, 2012 16:48 GMT-0000 Torsten Fabricius deleted the "," and "!" from a headline (help - I broke my theme 71
Mon 28 of May, 2012 23:42 GMT-0000 Marc Laporte 70
Mon 28 of May, 2012 22:13 GMT-0000 Marc Laporte 69
Thu 09 of Feb, 2012 18:51 GMT-0000 Marc Laporte 68
Thu 09 of Feb, 2012 18:09 GMT-0000 Marc Laporte 67
Sat 04 of Feb, 2012 03:42 GMT-0000 Marc Laporte Code Plugin modified by editor. 66
Sat 04 of Feb, 2012 03:40 GMT-0000 Marc Laporte 65
Sat 04 of Feb, 2012 03:09 GMT-0000 Marc Laporte 64
Sat 04 of Feb, 2012 03:05 GMT-0000 Marc Laporte utf-8 bad conversion 63
Tue 31 of Jan, 2012 20:49 GMT-0000 Jean-Marc Libs 62
Tue 31 of Jan, 2012 20:48 GMT-0000 Jean-Marc Libs Code Plugin modified by editor. 61
Tue 31 of Jan, 2012 20:47 GMT-0000 Jean-Marc Libs 60
Wed 09 of Nov, 2011 19:30 GMT-0000 Marc Laporte 59
Wed 09 of Nov, 2011 19:25 GMT-0000 Marc Laporte From a discussion on the mailing list (should work) 58
Thu 13 of Oct, 2011 13:02 GMT-0000 Marc Laporte 57
Sat 24 of Sep, 2011 17:58 GMT-0000 Marc Laporte 56
Sat 24 of Sep, 2011 17:54 GMT-0000 Marc Laporte 55
Sat 24 of Sep, 2011 17:50 GMT-0000 Marc Laporte 54
Tue 14 of Jun, 2011 01:48 GMT-0000 Marc Laporte 53
Tue 14 of Jun, 2011 01:22 GMT-0000 tinomartinez 52
Mon 13 of Jun, 2011 11:21 GMT-0000 Marc Laporte 51
Wed 27 of Apr, 2011 19:25 GMT-0000 Marc Laporte not working for some reason 50
Thu 24 of Feb, 2011 18:45 GMT-0000 Marc Laporte 49
Tue 11 of Jan, 2011 19:25 GMT-0000 Marc Laporte Thanks luci for documenting 48
Fri 05 of Nov, 2010 03:06 GMT-0000 Marc Laporte 47
Tue 02 of Nov, 2010 03:09 GMT-0000 Marc Laporte 46
Tue 02 of Nov, 2010 03:04 GMT-0000 Marc Laporte oups 45
Thu 28 of Oct, 2010 20:32 GMT-0000 Marc Laporte 44
Mon 20 of Sep, 2010 06:44 GMT-0000 Marc Laporte For Gaston: http://tiki.org/tiki-view_forum_thread.php?forumId=4&comments_parentId=38602 43
Sat 18 of Sep, 2010 06:28 GMT-0000 Gary Cunningham-Lee Removed some ...page... tags - clicking 22 times to see page content isn't good usability IMHO. 42
Wed 15 of Sep, 2010 16:09 GMT-0000 Rick Sapir / Tiki for Smarties 41
Thu 02 of Sep, 2010 02:09 GMT-0000 Gary Cunningham-Lee tikiwiki to tiki in urls. 40
Sun 15 of Aug, 2010 13:02 GMT-0000 luciash d' being ?‍♂️ 39
  • «
  • 1 (current)
  • 2