how toi theme a box and how to theme a file ?
Hi all. I have a template file called "foo.tpl.php", and I have $vars. How can i theme "foo.tpl.php" with $vars ? I have thinked that I need to use "theme" function(), but how ? And for a box ? M. -- Michel 'ZioBudda' Morelli michel@ziobuddalabs.net Sviluppo applicazioni CMS DRUPAL e web dinamiche (LAMP+Ajax) Telefono: 0200619074 Telefono Cell: +39-3939890025 -- Fax: +39-0291390660 http://www.ziobudda.net ICQ: 58351764 http://www.ziobuddalabs.it Skype: zio_budda http://www.ziodrupal.net MSN: michel@ziobuddalabs.it JABBER: michel@ziobuddalabs.it
On Wednesday 28 October 2009 5:35:35 am Michel Morelli wrote:
Hi all. I have a template file called "foo.tpl.php", and I have $vars.
How can i theme "foo.tpl.php" with $vars ?
I have thinked that I need to use "theme" function(), but how ?
And for a box ?
M.
You're actually putting the cart before the horse, it looks like. Somewhere in code, you'll need to format some data. OK, you want to use a template. So you first add a hook_theme[1] entry to define your theme key (foo), and you specify that it uses a template file (foo.tpl.php by default). Then you call: $output = theme('foo', $somevar, $anothervar, $somethingelse); in your module code where you want to turn $somevar, $anothervar, and $somethingelse into rendered HTML. With the theme hook setup correctly, that will result in foo.tpl.php getting called with $somevar, $anothervar, and $somethingelse, along with various other globally added variables. You can also use a template_preprocess_foo() function of your own to filter and mutate $somevar, $anothervar, and $somethingelse as needed or add more variables at that point. see the theming guide[2] for more information. You should start thinking from the point in code where you need to have something rendered, not from the template and then finding a place to put it. It will conceptually make more sense that way when you implement it. [1] http://api.drupal.org/api/function/hook_theme/6 [2] http://drupal.org/theme-guide/6 -- Larry Garfield larry@garfieldtech.com
participants (2)
-
Larry Garfield -
Michel Morelli