Andrew Simon
Andrew Simon

Reputation: 29

Live Edit Twig templates with phpstorm

Is it possible to setup Live Editing in Phpstorm with Twig templates? I know I can with html pages but it doesn't allow me to select my index.html.twig template.

Note: I am not using the symphony framework. Just twig templates.

Upvotes: 2

Views: 3050

Answers (3)

Rob Zaar
Rob Zaar

Reputation: 1

I've found gulp an easy way to do this. There is a tutorial that explains it well: https://www.chenhuijing.com/blog/drupal-101-theming-with-gulp-again/ You just need the browser sync part, but the rest may be useful for you. This includes clearing the whole cache which is not needed if you set up the render cache properly according to: https://www.drupal.org/node/1903374 As a bonus, I've found twig_tweak to be really useful since you don't need to enable xdebug, but can explore a variable eg {{ dd(node) }} which runs really fast. This solution does not need phpstorm but works very well. Just type, save and presto the browser(s) auto reload with your changes.

Upvotes: 0

Volodymyr Chumak
Volodymyr Chumak

Reputation: 766

You can use some file watchers (gulp, Guard) that will reload page after twig templates will be changed.

Upvotes: 0

lena
lena

Reputation: 93728

Not sure I follow you... You can't directly open .twig files in browser, but Live Edit does work for them. I have a .php file that renders twig using

echo $twig->render()

I create a javascript debug run configuration, specifying my php page URL (http://localhost/twig_test/index.php) as URL, press Debug, then start editing my .twig file => page is updated on-the-fly

Upvotes: 1

Related Questions