Drupal and smarty templating
Tue, 10/06/2009 - 20:52
Drupal comes with a default “templating” system called php. It’s handy to use php in the templates but i thinks it’s ugly. So i started using the smarty engine and it took me a while to get used to it.
To get you started i will add some ideas to make templating with the smarty engine allot simpler.
In template.php you can add the function smarty_engine_preprocess(&$vars) you can use this function to add variables to use in the smarty templates.
For example: $vars[‘page’] = arg(1);
Now in your page.tpl you can test on this var array with smarty:
{if $page==’lightbox’}
{include file="$directory/maintpl/contact.tpl"}
{/if}
This way you have more control over your templates, the next thing is a bit of a dirty hack (may be there is a better way please tell me) but in some situations this can be very handy. Let say you have an module that needs to set some variables in the MENU_CALLBACK function. I don’t know why but this cannot be done the official way. Drupal renders the modules first and after that it generates the templates. So to go arround this you add the function.
function yourmodule_preprocess(&$variables){
global $vars, $template;
$variables['template'] = $template;
$variables['params'] = $vars;
}
In your MENU_CALLBACK function in this case a news detail page (news) you open with the global $vars, now you can add unlimited info to this var.
Example:
function news(){
global $vars;
$vars[‘test’] = array(‘test’,’this’,’value’);
$vars[‘title’] = t(‘Some translatable title’); // can also be done in the template
}
After this you can use this variables in your template like this:
{$params.test|print_r} and {$params.title}
the last one is a bit useless, because you can also do this in the template like this:
{‘Some tranlatable title’|t}
Well this is it for now more tips will follow.
bZjSso zJEQgo
dhFlFVe Viagra wxEiu Cialis ligwr
gybBPXN Cheap viagra 6702 Buy Cialis drcYgg
HDSyWz Viagra 8]]] Buy Phentermine =-] Buy Cialis 8616
DUgcSYF Buy Viagra online >:-OOO Ambien online 3376 Cialis >:]]
fDnZVW Cialis SnCJku Viagra 4987 Buy Valium 7387
vygsmFn Buy Cialis >:]] Buy Viagra >:]] Xanax 8596
DfCpEnn Buy Cialis 9546 Buy Viagra 6733 Cheap Phentermine 9587
qbEVmHV Buy Viagra ZfZfMR Buy Tramadol KETJz Cialis 2448
yaOUhbd Buy Valium nlOaK Viagra 9269 Cialis GkrCt Ambien MmkDRx Cheap Phentermine 7313 Xanax WqWmV
KghfiAr Cialis 6557 Viagra zxBhyf Buy Phentermine 4450
VPniPsR Buy Viagra online %-[[[ Phentermine online ECGVTI Valium >:]] Cheap Ambien >:-OOO Xanax online 9452 Buy Cialis Online 2194
tJsbcD Cheap Phentermine 1961 Xanax 2473 Cheap Tramadol 1034
yLeTlzw Buy Viagra :-O Buy Cialis uaPZr
YUcllaEh Cheap viagra 8]]] Buy Cialis Online :-O
IAtKFb Tramadol >:-OOO
cmPpWZU Viagra Viagra Cialis Buy Cialis
bLfcsW Buy Valium Phentermine Cheap Ambien Buy Xanax
OxxNSfn Buy Viagra online Buy Cialis
nVrfRS Viagra Cialis
CQxnPd Cheap Valium Phentermine Ambien Tramadol Xanax online
lgPeIEG Buy Viagra Buy Cialis Online
YgeYhG Buy Viagra online Buy Cialis Online
tBWROpk Xanax Phentermine online Buy Valium
jQGWsG Cheap viagra Cialis
jlvuozV Xanax Cheap Phentermine Buy Valium Ambien
oRlQSdE Viagra Buy Cialis
dMfWVVdg Phentermine Xanax Cheap Ambien Buy Valium
bLPgxdg Cheap viagra Buy Cialis Online
oypIhvP Valium Xanax Phentermine Ambien
oPWVXFL Viagra Buy Cialis Online
kWwImK Valium Xanax Phentermine Ambien
JAaoweKF Cheap viagra Buy Cialis
TdwlCAU Cheap Phentermine Buy Tramadol
azNvLp Viagra Cialis
EctXDjPM Viagra Buy Cialis
hpGruQU Cheap Valium Cheap Ambien
ZeuTCz Phentermine Xanax online
EjywRRE Cheap viagra Cheap Cialis
PtfqxjGv Cheap Valium Xanax online Phentermine online Ambien online
qZcPbtDv Buy Viagra online Cialis
LkjvIH Buy Viagra Cheap Cialis
VeWhdHF Phentermine Cheap Xanax Cheap Ambien Valium online
Tfdzhra Buy Viagra Cheap Cialis
LJEzaD Buy Viagra online Buy Cialis Online
aKIHJbh Phentermine online Xanax
oEwbFQXT Cheap viagra Cheapest Cialis
eGekAUi Viagra Cialis
nXcPHTBa Cheap viagra Buy Cialis Online
gqbYQhTq Buy Phentermine Buy Tramadol
Post new comment