smarty-php / smarty-php/smarty

Compilation error ?

Open
#917 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
2.3k
Forks
709
PR merge metrics
No merged PRs in 30d

Description

Hello,

I had difficulty identifying a problem in a template. After reading the documentation I wonder if the behavior is normal or faulty.

$WXO_PRODUCT_CROSS and $WXO_PRODUCT_UP both have the value "".

The following code should not produce HTML output but it does. My error is a missing $ in the first condition.

            {if isset($WXO_PRODUCT_CROSS) && WXO_PRODUCT_CROSS ne ''}
                {if isset($WXO_PRODUCT_CROSS) && $WXO_PRODUCT_CROSS ne ''}
                <a href="#tab-articles-complementaires">{t}Additional articles{/t}</a>
                {/if}
                {if isset($WXO_PRODUCT_UP) && $WXO_PRODUCT_UP ne ''}
                <a href="#tab-articles-similaires">{t}Similar articles{/t}</a
                {/if}
            
                {$WXO_PRODUCT_CROSS}
            {/if}

The resulting code compiled by Smarty is:

<?php if ((isset($_smarty_tpl->tpl_vars['WXO_PRODUCT_CROSS']->value)) && 'WXO_PRODUCT_CROSS' != '') {?>

instead of

<?php if ((isset($_smarty_tpl->tpl_vars['WXO_PRODUCT_CROSS']->value)) && $_smarty_tpl->tpl_vars['WXO_PRODUCT_CROSS']->value != '') {?>

Is it normal for "WXO_PRODUCT_CROSS" to be interpreted as a string instead of causing a compilation error?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Smarty template shown in the issue and inspect the generated PHP condition. Compare the behavior of the missing-$ expression with the expected compilation output, then check whether existing parser or compiler tests cover this case. Done means the behavior is confirmed and, if faulty, covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.