Stel je wil iets themen in je module.
Je gebruikt het drupal theme systeem omdat je logic van presentatie wil scheiden.
De mogelijkheden:
Een ordinaire theme functie zoals in drupal 5
Begin niet te flippen als het niet direct gaat en onthou elke keer je een functie bijschrijft moet drupal dit te weten komen. Dus clear de cache telkens je een nieuwe functie of file bijschrijft (admin/settings/performance onderaan staat de clear cache knop)
<?php
function tandem_misc_theme() {
return array(
'sponser_link' => array(
'arguments' => array('link' => NULL),
),
);
}
?>
<?php
function theme_sponser_link($link) {
return check_url($link);
}
?>
<?php
function phptemplate_sponsor_link($link) {
$link = '<a href="http://ietsanders';
">http://ietsanders';
</a> return $link;
}
?>
Hoe doen we dat dan?
<?php
function tandem_misc_theme() {
return array(
'sponser_link' => array(
'template' => 'sponser_link',
'arguments' => array('link' => NULL),
),
);
}
?>
<?php
//tpl file
print check_url($link);
?>
<?php
function phptemplate_preprocess_sponser_link(&$variables) {
$variables['link'] = '<a href="http://ietsanders.com';
">http://ietsanders.com';
</a>}
?>
<?php
function tandem_misc_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
//print_r($node);
if ($node->type == 'tandem') {
switch ($op) {
case 'view':
//build the sponsor link for payment system here:
$link = '<a href="http://google.com';
">http://google.com';
</a>
$node->content['sponser_link'] = array(
'#value' => theme('sponser_link', $link),
'#weight' => 10,
);
break;
}
}
}
?>
Voor meer lees zeker de drupal documentatie http://drupal.org/node/165706 [2] en de api voor hook_theme http://api.drupal.org/api/function/hook_theme/6 [1]
Links
[1] http://api.drupal.org/api/function/hook_theme/6
[2] http://drupal.org/node/165706