Webstorm 9 missing live templates - webstorm

In Webstorm 9 name when I do [type func] + control + j to bring up live template, the func template does not appear. I have JavaScript ticked on the live templates.

In Settings/Editor/Live Templates/javaScript, select the 'func' template and change 'Applicable in' to javascript: expression, statement (tick the 'statement' checkbox)

Related

"no surround templates defined in this context" in WebStorm when Ctrl+Alt+J after selecting a text

In WebStorm in html file I select a text and do Ctrl + Alt + J and get "no surround templates defined in this context".
What do I wrong in it?
<i class="link to-be-copied">$SELECTION$</i>

PhpStorm create Live Templates with variables inside variable

I have a Snippet in Sublime Text that I'd like to migrate to PhpStorm
<snippet>
<content><![CDATA[date('${3:Y-m-d H:i:s}'${1:, strtotime('${4:+1 Day}'${2:, strtotime(${5:\$date})})})]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>mdate</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.php</scope>
</snippet>
That's the result in Sublime Text:
This is what I have so far in my Live Template:
date('$FORMAT$', strtotime('$DATE_MATH$', strtotime($DATE$)));
Edit:
My Goal is to get results like
date('Y-m-d H:i:s');
date('Y-m-d H:i:s', strtotime($date));
date('Y-m-d H:i:s', strtotime("+1 Day", strtotime($date)));
All using the same template. So I type mdate, tab.. select the optional chunk of code. if I press tab again, I go to the variables values else I can delete the chunk of code.
Please pay attention to the 6 stages of the snippet in the gif.
Thanks in Advance

How to get file name while creating snippets (Live Templates)

I am creating a snippet for my templates in Meteor and the only thing left to be perfect would be to know the file name in which that snippet was called.
What I have:
type: temp + tab
What I get:
<template name="">
</template>
What I want:
<template name="">
file_name.html
</template>
Live Templates is how "snippets" are called in WebStorm and other IDEA-based IDEs.
There is filename() function (fileNameWithoutExtension() has been added a few version later) that can provide such info/text for a variable. Official documentation.
Knowing that: add a variable into your template and then use the aforementioned function on it:
<template name="$END$">
$FILE$
</template>
Now click on "Edit Variables" button and use it there. Selecting "Skip if defined" will make that variable "non-editable" during template expansion.

ExpressionEngine content template

i have created channel called "news" and the channel field.
i have created template group called "news".
in news template group, there are "index" and "single" template.
what i want to do is when user go to url mydomain.com/news, it will show all the news with template from "index" template,
but if user go/ click to url mydomain.com/news/first-post, it will show the post with template from "single" template.
how can i achieve this?
i have tried to choose "single" template from "page" tab when i publish new content, but it didn't work.
the content url still show the "index" template
thanks.
URL routing in ExpressionEngine is as follows:
http://www.yourdomain.com/template-group/template/entry-url-title
It makes sense from an EE perspective that the news template is being shown when you go to mydomain.com/news/first-post. EE is looking for a template called first-post in the news template group. You can fix this in one of two ways:
1) Change the url you're looking for to mydomain.com/news/single/first-post. This should show your post.
2) If you don't want to show "single" in the URL, setup a condition in the main news template as follows:
{if segment_2}
{embed="news/single"}
{if:else}
... rest of your template code
{/if}
To keep this template cleaner, you might even want to create a news/main template so you can
{if segment_2}
{embed="news/single"}
{if:else}
{embed="news/main"}
{/if}
Up to you.

Inserting a { in an ExpressionEngine template file

I am trying to insert some analytics code into my ExpressionEngine template's footer files, but it treats the {}'s as a function call or something. Is there any way to make it so it understands that EE shouldn't execute what's inside the braces?
I've already tried inserting backslashes and it doesn't seem to work.
Any help would be much appreciated.
ExpressionEngine's Template Class parses curly braces {} as template variables.
Because many programming languages use curly braces, this can cause problems by ExpressionEngine replacing JavaScript curly braces as Template Variables.
For example, the following JavaScript with curly braces all on one line:
<script>var addthis_config = { 'ui_click': true };</script>
Will be parsed by ExpressionEngine as a template variable and rendered as:
<script>var addthis_config = ;</script>
You'll notice everything starting at the opening { and ending with the closing } curly brace gets parsed and replaced! As a workaround, you can place the braces on separate lines and avoid this problem:
<script>
var addthis_config = {
'ui_click': true,
'data_track_clickback': true
};
</script>
If you've written a JavaScript function that expects values from ExpressionEngine, just place your braces on separate lines — which is a good coding convention and is optimal for readability.
What is your Debug preference in EE? It should be set to "1" (recommended). If it's currently at "0" try changing the setting value to "1". In some cases there are possible issues with non-EE {} characters used while debug is set to "0".
You can change the Debug Preference from
CP => Admin => System Administration => Output and Debugging => Debug Preference.
Putting the {} braces on separate lines would also work, but that Debug setting ("1") is highly recommended, and maybe even why this "bug" isn't fixed.
Separate your analytics code into a separate template.
It's probably because you have the analytics code INSIDE another EE loop and so it's trying to parse it as a template variable.
So isolate the code if you need it within the loop and create an embedded template to include.
Thus, create an include called .analytics.
In the .analytics template, do the following (I'm using Google Analytics as an example):
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
NOTE: Using this method, keep the template as a normal template, do NOT change it to a javascript template because you are using the <script type="text/javascript"> tags inside the template.
Then, in your main template, do a simple:
{embed="template_group/.analytics"}
And you will be good to go.
Try the Protect Javascript config variable. I've used it to mix/match EE vars and JS several times.
EE 1.x
$conf['protect_javascript'] = 'y';
Reference
EE 2
$config['protect_javascript'] = 'y';
Reference
You should be using the hidden config varable protect javascript
$config['protect_javascript'] = 'y';
Have you tried commenting out the whole block of Analtics code using EE template comment tags? i.e.
{!--
Your comments will go in here.
You can even span it across multiple lines.
--}
From here http://expressionengine.com/user_guide/templates/commenting.html
I recommend you to avoid inserting (or trying to insert) raw JS into HTML templates. You can create a different template, with type JavaScript instead of HTML, then you can either add it at the head with a script tag, or {embed="js/piece-of-raw-javascript"}