Two or more code type in one file

I have some smarty adddon.callendar.tpl file loaded dynamicly from other template file with some JavaScript code like this:

function jqGenerateCallendar() {
    // some JavaScript Code
}
{/literal}


Is it possible make PHPStorm to recognize this file as Smarty and JavaScript code in the same time ?
I need this to reformating and for syntax
I can't add JavaScript definition like this here:

<script type="text/javascript" language="JavaScript">


is it possible to do ?

8 comments
Comment actions Permalink

Hi there,

Is that the only content in such file?

If so -- apply step #3 and use "JavaScript" (will be used instead of default "HTML").

0
Comment actions Permalink

something like this but I have much more such files.
Is there some comment tag for example:

// @lang: JavaScript

or can I configure that all files with .tpl are smarty and can have JS
now I can configure file mask for speciffic language:

JavaScript:
*.js
*.script

PHP:
*.php
*.phtml

can I inverse this configuration and specify languages for  files ?

*.js:
JavaScript

*.tpl
Smarty
JavaScript

and so on

0
Comment actions Permalink

Unfortunately No.

By default all *.tpl files ARE Smarty with HTML as outer language (same as all *.php files are PHP with HTML as outer language).

If you want all *.tpl files to have JavaScript as outer language (instead of default HTML) then you have to assign it manually (NOTE: you can apply such setting to folders as well -- in such case all files in such folder and subfolders will have that outer language).

0
Comment actions Permalink

1) The same pattern (e.g. fie extension -- *.tpl) can only be associated with single file type.

2) Associating *.tpl with JavaScript in File Types will treat it as JavaScript -- no Smarty functionality will be available there.

0
Comment actions Permalink

Did you notice custom tag {script ...} before {literal} in the original screenshot?

That ticket (and another related one) allows you to inject custom language (by creating custom Language Injection rule) in such custom tags. In your example/screenshot you have no tags at all -- just plain JavaScript.

You may try and inject JS into {literal} .. but it will affect ALL {literal} tags in your project.

0
Comment actions Permalink

As I writed I can use only plain javascript in this file so right now I do not have any idea how to use language injection with it

0
Comment actions Permalink

I used this

Here is how to do this for the original request:
1) Open Settings|Language Injections
2) Click [+] and choose "Generic Smarty"
3) Choose "JavaScript" in "ID:" field
4) Write the following pattern in "Place patterns":
 

+ smartyLiteralTag() 

 5) Click "OK"

0

Please sign in to leave a comment.