How do I use Smarty templating engine with my modules?

Melmacian - April 14, 2009 - 20:51

I already have a custom theme running with Smarty 2.6.22 in Drupal 5 and I would like to use smarty also with my own modules.

How do I do that?

Any examples?

Thanks!

It's "working"

Melmacian - April 14, 2009 - 23:08

Ok, I got it somewhat working. But I needed to comment out this line from themes/engines/smarty/smartytemplate.php:
require_once realpath(ENGINE_PATH.'/inc/common.php');
If it is enabled I get following error:

( ! ) Fatal error: require_once() [function.require]: Failed opening required '' (include_path='.:/usr/share/php:/usr/share/pear') in /home/frank/mysite/themes/engines/smarty/smartytemplate.php on line 19
Call Stack
# Time Memory Function Location
1 0.0002 64784 {main}( ) ../index.php:0
2 0.0029 256868 drupal_bootstrap( ) ../index.php:13
3 0.0121 701868 _drupal_bootstrap( ) ../bootstrap.inc:822
4 0.0183 1170624 _drupal_bootstrap_full( ) ../bootstrap.inc:885
5 0.0386 2554500 module_load_all( ) ../common.inc:1856
6 0.1127 6552432 drupal_load( ) ../module.inc:14
7 0.1129 6560304 include_once( '/home/frank/mysite/modules/mymodule/mymodule.module' ) ../bootstrap.inc:512
8 0.1134 6580432 require_once( '/home/frank/mysite/modules/mymodule/onefileinmymodule.php' ) ../mymodule.module:3
9 0.1144 6626016 require_once( '/home/frank/mysite/themes/engines/smarty/smartytemplate.php' ) ../thelisting.php:14

And there is no file called common.php in themes/engines/smarty/inc.
Version: // $Id: smartytemplate.php,v 1.6 2005/12/31 09:24:02 tclineks Exp $

Is this package broken or what? I'm using version 5.x-0.1 ( http://ftp.drupal.org/files/projects/smarty-5.x-0.1.tar.gz ) and 2.6.22 version of Smarty.

Any ideas if this could lead in some problems later on?

But this is it is working (if the above line is removed):

require_once('themes/engines/smarty/smartytemplate.php');

// this is from a function:
$smarty = new SmartyTemplate('modules/mymodule/templates');

$smarty->assign("test","value");

$page_content = $smarty->fetch('index.tpl');

return $page_content; // return content for my module

module/mymodule/templates/index.tpl

<p>Template test for a module. Here's a variable: {$test}</p>

 
 

Drupal is a registered trademark of Dries Buytaert.