Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
How Use {Php} tag in smarty 3.1

 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
dev.himanshu
Smarty n00b


Joined: 23 Nov 2011
Posts: 1

PostPosted: Thu Nov 24, 2011 4:32 am    Post subject: How Use {Php} tag in smarty 3.1 Reply with quote

I want to use {php} tag in smarty templete.
i try this
The constants
SMARTY_PHP_PASSTHRU
SMARTY_PHP_QUOTE
SMARTY_PHP_REMOVE
SMARTY_PHP_ALLOW
have been replaced with class constants
Smarty::PHP_PASSTHRU
Smarty::PHP_QUOTE
Smarty::PHP_REMOVE
Smarty::PHP_ALLOW
but that not work...
help me for that.
Back to top
View user's profile Send private message Send e-mail
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7286
Location: Lincoln Nebraska, USA

PostPosted: Fri Nov 25, 2011 12:09 am    Post subject: Reply with quote

you must use SmartyBC.class.php for the php tag.
Back to top
View user's profile Send private message Visit poster's website
Billie67
Smarty n00b


Joined: 20 Oct 2011
Posts: 2

PostPosted: Sat Dec 03, 2011 8:30 am    Post subject: Reply with quote

Here is my directory structure:
./smartytest.php
./smarty31/* (libs, etc.)
./plugins/block.sayhi.php
The PHP code that initializes smarty is:
require_once('smarty31/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = getcwd() . '/templates';
$smarty->compile_dir = getcwd() . '/templates_c';
$smarty->plugins_dir[] = getcwd() . '/plugins';

The PHP code for the plugin is:
<?php
function smarty_block_sayhi($params, $content, $smarty, $open) {
if (!$open) {
return 'Hello: ' . $content;
}
}
?>

The error message I get is this:
Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "/mypath/phptests/templates/page.tpl" on line 11 "{sayhi}" unknown tag "sayhi"'
When the plugin was under the smarty31/libs/plugins directory, it loaded fine. Does this sample code not initialize Smarty correctly?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4673
Location: Hamburg / Germany

PostPosted: Sat Dec 03, 2011 10:01 am    Post subject: Reply with quote

starting with Smarty 3.1 you must use setter functions to set dir directories

Code:

$smarty-setTemplateDir = ( './templates';
$smarty->setCompileDir = ('./templates_c');
$smarty->addPluginsDir = ('./plugins');
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP