TemplatesPackage

How to use Smarty Templates in your Package

Created by: spiderr, Last modification: 03 Nov 2008 (01:02 UTC) by charles
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:
"bitpackage:yourpkg/yourpkg_show_data.tpl"
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:

<?php
OLD WAY
: {include file=tiki-directory_bar.tpl}
NEW 
WAY:{include file="bitpackage:directory/directory_bar.tpl"}
?>


In PHP files, the smarty load and assigns should look like

<?php
OLD WAY
$smarty->assign('mid''tiki-my_tiki.tpl');
NEW 
WAY$gBitSmarty->assign('mid''bitpackge:users/my_bit.tpl');
?>

or

<?php
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.

Related Items

Packages » Unmaintained Packages

These packages are no longer maintained and are not supported any longer.

  •    •    •    •    •    •    •    •    •    •  

Online Help » Packages

  •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •