This Question is Possibly Answered

1 "correct" answer available (4 pts) 2 "helpful" answers available (2 pts)
4 Replies Last post: Nov 17, 2013 8:21 PM by Andriy Bazanov  
olvit  Newbie 1 posts since
Jan 8, 2005
Currently Being Moderated

Oct 10, 2013 3:12 PM

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

Olivier VIT Newbie 2 posts since
Nov 15, 2013
Currently Being Moderated
Nov 15, 2013 5:11 PM in response to: olvit
Re: How to protect propriertary {{syntax}} within JS code ?

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>
Andriy Bazanov Master 3,991 posts since
May 28, 2010
Currently Being Moderated
Nov 16, 2013 4:27 PM in response to: olvit
Re: How to protect propriertary {{syntax}} within JS code ?

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.

Olivier VIT Newbie 2 posts since
Nov 15, 2013
Currently Being Moderated
Nov 17, 2013 1:51 PM in response to: Andriy Bazanov
Re: How to protect propriertary {{syntax}} within JS code ?

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

Andriy Bazanov Master 3,991 posts since
May 28, 2010
Currently Being Moderated
Nov 17, 2013 8:22 PM in response to: Olivier VIT
Re: How to protect propriertary {{syntax}} within JS code ?
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.

More Like This

  • Retrieving data ...