Hello everybody,
I am really in need of some pointers: I am creating modules and want the output themed by smarty.
Here is my code so far:
Function to take over frontpage:
function frontpage_menu($may_cache) {
if ($may_cache) {
$items = array();
$items[] = array(
'path' => 'frontpage',
'title' => t(''),
'callback' => 'yoyo',
'access' => TRUE,
'type' => MENU_SUGGESTED_ITEM);
return $items;
}
}
So far, so good, this works as expected, now I want to load my new frontpage-template (frontpage.tpl) and have those {smartyplaceholders} replaced with the actual content.
Failure #1:
function yoyo() {
$smarty->assign('feature', "TESTTEST");
$output = _smarty_default("frontpage", $vars,'');
print $output;
}
Failure #2:
function yoyo() {
$smarty->assign('feature', "TESTTEST");
$output = $smarty->fetch(drupal_dir ."/". path_to_theme() . "/frontpage.tpl");
$output = smarty_page($output);
print $output;
}
Neither of those two functions replace the assigned variable, which drives my crazy.
I would really appreciate it if someone would help out and explain to me what the easiest & most efficient way to create modules which use smarty is.
Thanks alot.
Comments
ahem, I have since realized
ahem, I have since realized that the above code is crap, here is my newest revision, which kind of works, here's the problem:
The variable "name" that is smarty-assigend in do_it() is only available in "frontpage.tpl", and the vars that are supplied to "_smarty_callback()" are only available in the "altpage.tpl"-template.
However, I need to have access to the "$vars" from the "frontpage.tpl" template.
Basically, all I want is an alternative "page.tpl"-template which I can call in a similar manner to theme('page'....).
Can somebody help? please? thanks!
Since front_page.module
Since front_page.module doesn't publish through a themeable function this is going to be tricky.
front_page.module isn't really suited for such.
If you're in need of more general examples say so.
See the attached patch to front_page.module to see how to introduce themable output.
You could then define a smarty_front_page_text(_yes) to control output.
This isn't really recommended as it essentially breaks the module by hijacking it.
Just read through my reply there
Just read through my reply there -- very robot-esque =p
thanks!
Thanks for the effort, Travis.
I am currently not using the front_page.module although I might just try it with the supplied patch and see how it works out.
Nonetheless, I would really appreciate a more general example as I need this functuality for pages other than the frontpage.
Thanks you again,
Till
You mention you need this
You say there you need this for pages but mention theming a module as well.
Still unclear on your goals -- I'm not clear if you're trying to accomplish something for specific existing pages or for a module you're writing.
If the latter: http://drupal.org/node/306
Let me know