By ollie222 on
I have a custom module that takes a few arguments via the url, does some work on them and produces page content by returning the result of theme() as $content and this is inserted into page.tpl.php as standard.
Most of the time the themes standard page.tpl.php suffices but I have a need to be able to return the content in a different page.tpl.php depending on one of arguments passed or a calculation that the module does based upon the arguments and database data.
Can someone please tell me the correct way to do this or direct me to an example of this?
Comments
You can implement the
You can implement the preprocess page function in your module or theme. So for example you would implement the following in your module:
This way if your condition is met, the output of your page will be rendered through page-custom.tpl.php. You'll have to clear the cache for your new template file to be picked up.
or you can use
or you can use :
in the template.php to select the page.tpl based on url
--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com
Thanks
Thanks for the replies and using the above preprocess_page methods I can place a 'page-custom.tpl.php' file in the theme folder and it does work however I have a couple of issues with it.
1. How can I make it pick up a custom template file in the modules folder not the theme's? While not essential for this project it would be nice to be able to package a page template with module.
2. The main part of the module already performs the queries to work out if the page template needs changing and it seems a bit wasteful to have to perform these same operations in the preprocess_page hook. Is it possible to set the template file from the main part of the module or at least pass the result to the preprocess_page hook?
Thanks for the help on this, it's much appreciated.