Skip to content

{php} tag doesn't work when delimiter is '<%' and '%>' #445

@ngmy

Description

@ngmy

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

uwetews commented on May 16, 2018

@uwetews
Contributor

If you set

$smarty->php_handling = Smarty::PHP_ALLOW;

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

ngmy commented on May 17, 2018

@ngmy
Author

I tried not to set $php_handling, but the {php} tag did not work.

test2_1.php

<?php

require './vendor/autoload.php';

$smarty = new SmartyBC();
//$smarty->php_handling = Smarty::PHP_ALLOW;
$smarty->left_delimiter = '<%';
$smarty->right_delimiter = '%>';
$smarty->display('./test2_1.tpl');

test2_1.tpl

<%if true%>
test2_1 if
<%/if%>

<%php%>
echo "test2_1 php";
<%/php%>

output:

$ php test2_1.php 
test2_1 if

<%php%>echo "test2_1 php";
<%/php%>
uwetews

uwetews commented on May 17, 2018

@uwetews
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ngmy@uwetews

        Issue actions

          {php} tag doesn't work when delimiter is '<%' and '%>' · Issue #445 · smarty-php/smarty