phpstorm 7 smarty-like statements in embedded javascript (in html template)

Hi!

I often embed JavaScript-code in HTML templates via tag script, and use Smarty-like statements in the code like this:

<script>
{if $debug}
    var debug = true;
{else}
    var debug = false;
{/if}
</script>

but PhpStorm shows a lot of warnings - such as "expected something else," or, if I comment out the statement:

<script>
/* {if $debug} */
    var debug = true;
/* {else} */
    var debug = false;
/* {/if} */
</script>

"Duplicate" and so on, and it's annoying. Is there a way to make PhpStorm understand these statements as I expect (like if-statement)?

2 comments
Comment actions Permalink

Hi there,

IDE does NOT follow the if-then-else branching logic (which is difficult to implement properly even in more appropriate languages like PHP/JavaScript itself) and treats content as is .. which results in marking debug variable as "duplicate declaration" (even in actual Smarty template).

The possible way of making your specific example to work is to try something more simple, e.g. something like this:

<script>
    var debug = {$debug};
</script>

0
Comment actions Permalink

thanx

it was a simple example, in the real project is more complex branching. will either accept or change the logic of templates.

0

Please sign in to leave a comment.