History of TemplatesPackage

Version 8


How to use Smarty Templates in your Package

Created by: xing, Last modification: 18 Dec 2005 (07:53 UTC) by xing
bitweaver uses the Smarty Template Engine.

NOTE: See the BitSmarty class in the KernelPackage to see how the work is actually done.

bitweaver uses Smarty's Custom Template Resource technique to load templates. bitweaver also follows TikiWiki''s wonderfully flexible ablility to automatically override templates by creating a copy of that template in your own ThemeStyle.

The custom resource declaration looks like "resourcetype:resourceowner/resourcename.tpl". Note, this is NOT a path. An example would be:
So, resourcetype = 'bitpackage', resourceowner = 'yourpkg', and resourcename = 'yourpkg_show_data.tpl'. To get this file, the actual path KernelPackage would look for is "/path/to/bitweaver/yourpkg/templates/yourpkg_show_data.tpl" (though first it would check for a Style override - see below...)

To compare how templates should be invoked let's compare old and new. In .tpl files, the include should look like:

Please enter a valid 'page_name', 'page_id' or 'content_id' to include in this page.


Please enter a valid 'page_name', 'page_id' or 'content_id' to include in this page.

In PHP files, the smarty load and assigns should look like
OLD WAY: $smarty->assign('mid', 'tiki-my_tiki.tpl');
NEW WAY: $gBitSmarty->assign('mid', 'bitpackge:users/my_bit.tpl');
OLDWAY: $smarty->fetch("debug/tiki-debug_console_tab.tpl");
NEW WAY: $gBitSmarty->fetch( "bitpackage:debug/debug_console_tab.tpl' );

How are templates searched for?

When a template needs to be fetched, the BitSmarty class will look in several places for the template. Here is how it works:
  1. A template is requested, and BitSmarty has registered get_bit_template() as the default handler function, so that function gets called.
  2. get_bit_template() checks to see if we are requesting a "bitpackage' resource type. If so, it will first check the active ThemeStyle to see if a templatte file with the requested resource name in the styles folder (themes/styles/matrix/header.tpl for example). If it exists in the theme, it will read in that file. If the template file does not exist, it will check in the resource owner's 'templates' folder. If it exists there, it will read in that file. If it is not either place, you will get a "MISSING TEMPLATE" error message.

modules templates are a slightly different beast, and more to come on them.

Page History
03 Nov 2008 (01:02 UTC)
Current • Source
View • Compare • Difference • Source
View • Compare • Difference • Source
View • Compare • Difference • Source
Danny Staple83.151.201.1677
View • Compare • Difference • Source
View • Compare • Difference • Source
View • Compare • Difference • Source