See Larry Garfields response for the full answer. He provided an excellent example.
in Your module:
mymod_foo calls theme() to make sure that the output is themeable. (by phptemplate or other theme engines)
theme_foo_or_something() provides the default view if not overriden by the theme.
in the template.php file for the php template theme:
phptemplate_foo_or_somthing() matches up the foo_or_something.tpl file with the intercepted theme function.
in the foo_or_something.tpl The overriden template is specified by the designer.
Larry's post is as follows: <snip>
#################################################
module code - mymod.php
#################################################
function mymod_foo() {
$data = array('foo' => 'bar');
return theme('foo_or_something', $data); }
function theme_foo_or_someting($data) {
return "something you do with $data that generates a string"; }
#################################################
template.php code
#################################################
function phptemplate_foo_or_something() {
return _phptemplate_callback('foo_or_something', $data); }
#################################################
foo_or_something.tpl.php
#################################################
<h1>I want to output value of $foo here</h1>
________________________________
From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Cyberswat Sent: Tuesday, April 10, 2007 1:08 PM To: support@drupal.org Subject: Re: [support] Templating in Drupal 5.1 - the cleanest way to do it?
Thanks for the response. I understand the approach you outline and have been using it exclusively so far. I'm starting to work with structures that are more complex than my original example and would ultimately like to task a designer to create/modify the tpl files without editing the module at all. How do I go about invoking the theme engine to accomplish this in a similar to my original example?
On 4/10/07, Metzler, David metzlerd@evergreen.edu wrote:
Easiest way is the the following. In this case, the html output represented by $foo is presented in the content area of page.tpl. Note you don't need custom theme functions and custom tpl files to do this. Now you could invoke the theme engine as well, but I wanted to make sure you understood this easier way first. Dave
________________________________
From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Cyberswat Sent: Tuesday, April 10, 2007 11:47 AM To: support@drupal.org Subject: Re: [support] Templating in Drupal 5.1 - the cleanest way to do it? I have another question regarding this subject. If I create a custom module how do I use the templating engine to work with the output of the module? I know this code is bad, but it summarizes what I would like to do. Any help is appreciated as I'm starting to feel dense from not being able to figure this out. ################################################# module code - mymod.php ################################################# function mymod_menu($may_cache) { $items = array(); $items[] = array('path' => 'mymod_view', 'title' => t('mymod_view'), 'callback' => 'mymod_foo', 'type' => MENU_LOCAL_TASK, 'access' => user_access('view mymod'), 'weight' => 0, ); return $items; } function mymod_foo() { $data = array('foo' => 'bar'); $output = '<h1>Here is the value of '.$data['foo'].' here. </h1>'; return $output ; }
-- [ Drupal support list | http://lists.drupal.org/ ]