- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 719
Closed
Description
Hi,
I use PHP 5.6.30 and Smarty 3.1.32.
When I changed delimiter to '<%' and '%>', {php} tag didn't work.
{php} tag works when delimiter is '{' and '}'
test1.php:
<?php
require './vendor/autoload.php';
$smarty = new SmartyBC();
$smarty->php_handling = Smarty::PHP_ALLOW;
$smarty->display('./test1.tpl');
test1.tpl:
{if true}
test1 if
{/if}
{php}
echo "test1 php";
{/php}
output:
$ php test1.php
test1 if
test1 php
{php} tag doesn't work when delimiter is '<%' and '%>'
test2.php:
<?php
require './vendor/autoload.php';
$smarty = new SmartyBC();
$smarty->php_handling = Smarty::PHP_ALLOW;
$smarty->left_delimiter = '<%';
$smarty->right_delimiter = '%>';
$smarty->display('./test2.tpl');
test2.tpl:
<%if true%>
test2 if
<%/if%>
<%php%>
echo "test2 php";
<%/php%>
output:
$ php test2.php
test2 if
<%php%>
echo "test2 php";
<%/php%>
{php} tag works when delimiter is '<=' and '=>'
test3.php:
<?php
require './vendor/autoload.php';
$smarty = new SmartyBC();
$smarty->php_handling = Smarty::PHP_ALLOW;
$smarty->left_delimiter = '<=';
$smarty->right_delimiter = '=>';
$smarty->display('./test3.tpl');
test3.tpl:
<=if true=>
test3 if
<=/if=>
<=php=>
echo "test3 php";
<=/php=>
output:
$ php test3.php
test3 if
test3 php
Activity
uwetews commentedon May 16, 2018
If you set
Delimiters '<%' and '%>' will be interpreted as PHP ASP tags and not as Smarty tag. see https://www.w3resource.com/php/syntax/syntax.php
Smarty {php}{/php} tags of SmartyBC does not require Smarty::PHP_ALLOW setting.
See https://www.smarty.net/docs/en/language.function.php.tpl and https://www.smarty.net/docs/en/variable.php.handling.tpl
So just do not set php_handling to Smarty::PHP_ALLOW
ngmy commentedon May 17, 2018
I tried not to set
$php_handling
, but the {php} tag did not work.test2_1.php
test2_1.tpl
output:
uwetews commentedon May 17, 2018
You are right. You don't need to set Smarty::PHP_ALLOW to enable the {php} tag.
However you can't use the PHP delimiters <% and %> as Smarty delimiter.There is no solution.