5

I'm working with Phalcon in Netbeans. I see I can use twig plugin for template highlighting for volt files. I am using phtml files and want highlighting for volt (twig) and php. Is this possible?

Also related - Netbeans keeps duplicating my phtml view files and adding the extention .phtml.php to them. How can I fix that?

Ally
  • 955
  • 1
  • 15
  • 33
  • No answer was accepted because no answer fully answered my question - how to get syntax highlighting for volt and php in same file. This was almost 2 years ago now, and since then I have been using phpStorm for web dev. – Ally Jan 27 '16 at 16:52
  • Using both volt & PHP in same file hurts MVC and idea of using template engines at all.. So for that purpose you should write yourself a highlight logic. – yergo Jan 28 '16 at 09:40
  • Yes I try to avoid using php syntax in volt, but have had to in the past due to bugs in phalcon where certain things wouldn't work. – Ally Jan 28 '16 at 13:58

3 Answers3

17

Go to Tools->Options->Miscellaneous->Files right to "File Extensions" press "create" and type there "volt". After that in "Associated File Type (MIME)" choose "TWIG (text/x-twig)". Restart IDE.

Apostle
  • 171
  • 1
  • 6
3

I use twig syntax in PHPStorm and everything works fine. Look at Netbeans settings(or the twig plugin settings) and try to add new file extensions to be recognized as twig files like *.volt and *.phtml. If you can't figure out how to make volt files be recognized as twig files, as a last resort, you can change all you template files to .twig then change Volt settings to recognize .twig files as a Volt template, like:

//Registering Volt as template engine
$di->set('view', function() {

    $view = new \Phalcon\Mvc\View();

    $view->setViewsDir('../app/views/');

    $view->registerEngines(array(
        ".twig" => 'Phalcon\Mvc\View\Engine\Volt'
    ));

    return $view;
});

About .phtml.php isn't Netbeans creating these files, it's Phalcon. All templates are compiled to .php. They will be put in the same folder of your template unless you configure your Volt engine properly. More info about this here.

cvsguimaraes
  • 12,910
  • 9
  • 49
  • 73
  • Thanks @cvsguimaraes I already have twig plugin working in netbeans to recognise .volt and .phtml files as twig. Code highlighting etc works, but not for lines of php. So I want highlighting for twig & php in same file! ....interesting point you explained about phalcon creating the .php files. I had no idea about that - I thought netbeans was going mad! :) – Ally Jun 01 '14 at 10:38
  • @Ally In PHPStorm you can define a syntax highlight for only a fragment of the file(e.g select all PHP code and set the highlight to php), but I've searched a while and didn't found this functionality in Netbeans. – cvsguimaraes Jun 02 '14 at 14:32
  • @Ally why you using PHP in Volt templates anyway? The basic idea of templates is to receive data that's **already processed** and just create a view for those data. If you truly need to use some external function in your template you can add it as custom Volt method. – cvsguimaraes Jun 02 '14 at 15:31
0

Go to Tools->Options->Miscellaneous->Files. Click New "File Extensions" and type there "volt". After that in "Associated File Type (MIME)" choose "TWIG (text/x-twig)". Restart IDE.

Deepti Gehlot
  • 617
  • 7
  • 8