How to protect propriertary {{syntax}} within JS code ?

Hi

In Google Tag Manager you can paste JavaScript code that referrers to custom macros designed to extract data from web pages.

The syntax for a custom macro is "{{custom macro name}}"
Can I tell PhpStorm to ignore those snippets so that syntaxe validation, code reformating, etc... still works when those macro references are incoporated into the JS source code ??

Thanks for your help

4 comments

Up
Anyone can suggest an approach to enable such code in PhpStrom ?

<script>
function() {
var cj_page = document.location.pathname+document.location.search ;
/* tunnel d'achat */
console.log ('pageNameAlternate: '+{{m_pageNameAlternate}} );
console.log ('pageName: '+{{m_pageName}} );
if ( {{m_pageNameAlternate}})
{ cj_page = {{m_pageNameAlternate}}; }
else if ( {{m_pageName}} ) {
    { cj_page = {{m_pageName}}; }
}
return cj_page; }

</script>
0

Hi there,

The syntax looks similar to Handlebars/Mustache templates.

See if installing Handlebars/Mustache plugin (Settings | Plugins | Browse Repositories...) will help here (obviously, you will need to associate such files with that plugin in "Settings | File Types").

https://github.com/dmarcotte/idea-handlebars

Can I tell PhpStorm to ignore those snippets so that syntaxe validation, code reformating, etc... still works when those macro references are incoporated into the JS source code ??

Just like that -- No. It has to be supported via plugin in order to not to be treated as invalid code.

0

Hi Andriy,

That's pretty much OK with that plugin, it just complains about + signs used to concatenate variables in JS
It's like if Handlebars/Mustache was only designed to generate HTML content but not Javascript within the HTML page, surprising, no ?
javascript mustache.png

0
It's like if Handlebars/Mustache was only designed to generate HTML content but not Javascript within the HTML page, surprising, no ?

I'm not using this plugin or any of these templating systems myself and therefore cannot really comment on how it actually works.

I may only suggest asking this question on Issue Tracker of the actual plugin (but check existing/closed tickets first) -- plugin author should be able to say what you may be doing wrong (if it is actually expected to work) or if he can do anything about it (now or in one of the future versions). If author will say that it's not his fault (since this seem to be warning from JavaScript support side), then either wait for any JB devs to reply here .. or submit a ticket on WebStorm Issue Tracker.

0

Please sign in to leave a comment.