[support] Using the node theme or a template from custom module

DTH david at hartster.org
Thu May 31 08:22:34 UTC 2012


Yeah, I think I was over- (or realistically under-) thinking things
with my desire to reuse my node templates. I just used the theme layer
and created a separate theme template modelled on my node.tpl.php

function example_page(){
  return array(
      "#column1" => "<p>Lorem Ipsum</p>",
      "#column2" => "<p>Foo Bar</p>",
      "#theme" => "two_column_page",
   );
}

Thanks for the help.

> From: Blair Wadman <blair at wadmanconsulting.com>
>
> If you pass this through a theme function, you can then create a custom template file.
>
> Something like this:
>
> function example_page(){
>  $data = 'Lorem ipsum etc';
>  $output = theme('my_custom_template', $data);
>
>  return $output;
> }
>
> Then you can create a template in your theme layer called my_custom_template.tpl.php
> In there, you can print $data and wrap it in the <p> tags.
>
> Don't forget to clear cache and rebuild theme registry.
>
> Cheers
>
> Blair

> On Wednesday, 30 May 2012 at 15:34, Joel Willers wrote:
>
>> Since it's not a node, it won't render like a node. Does it use page.tpl.php? Sadly, I'm no expert in template files. I'd be interested in the solution to this, so if you figure it out, could you respond and post it? Thanks!
>>
>> Joel
>>
>>
>> To: support at drupal.org (mailto:support at drupal.org)
>> Subject: [support] Using the node theme or a template from custom module
>>
>> I've got a custom module for D7. On some pages, it returns html. I'm using this in the page callback
>>
>> function example_page(){
>> return array(
>> "#type" => "markup",
>> "#markup" => "<p>Lorem ipsum etc</p>",
>> );
>> }
>>
>> It works fine, but the page (obviously) doesn't use my node.tpl file, and so it looks different from the rest of the site. It's not that the node.tpl file is particularly complex, but it does some things like wrap the node content in divs that have styling applied to them etc.
>>
>> I could use #prefix and #suffix to wrap the above output in these divs, but is there either a) some way to reuse my node template or b) what's the best way to create a quick clone of the node template that can be reused in render arrays every time I want to output pages from my module. Do I have to call a theme function by #theme or is there a way to use an actual template file?


More information about the support mailing list