Jump to content

ProcessWire 3 and templating languages


porl
 Share

Recommended Posts

Hi all

I'm about to try out ProcessWire 3 but I've been out of the loop for a while. I used to use Twig as a templating language (I wrote the first very naive module to use Twig on here but switched over to the much better ones developed by others). Whilst I'm not attached to Twig to the point where I wouldn't use anything else I'm still not a fan of "raw" PHP as the templating language for my "views".

Is ProcessWire 3 at a stage where other templating languages can be used? I know that some of its design should make it simpler to make those kinds of modules but have any been made? If not is there anyone working on one (and ideally a forum thread I can see any progress)?

I understand that these things take time, so please don't think I'm demanding anything or expecting someone to knock something up for me overnight. I am just wondering where things are at so I know if I should look into it further or hold off for now.

Thanks

Link to comment
Share on other sites

@porl: I'm not aware of any solutions specifically built for 3.x yet, apart from the simple tag replacement module File Compiler Tags bundled with the core package.

While someone will no doubt put together a File Compiler based templating engine module in the near future, currently your best bet is going with one of the existing solutions (such as Template Engine Factory @pwired linked to earlier).

Link to comment
Share on other sites

In the weekend I just put together my Latte engine module - should have done this way earlier, it's much clearer and better than my previous non-module attempt. I'll share it after using it for a while to see everything works as expected. It's for PW3.

  • Like 2
Link to comment
Share on other sites

If I was to find that Latte didn't suit for some reason do you think your module could be easily adapted to Twig or other templates? Or is the Latte "engine" pretty well entwined with the module?

Edit: Sorry I should be clear - I'm not asking if you could do it for me, just if it might be feasible for me to "swap out engines" if needed or if it would be basically a rewrite anyway and not worth it.

Link to comment
Share on other sites

Well it's not impossible to do but I don't plan such a feature.

There's already the module Template Engine Factory which is similar to your concept. And there's also Latte engine for that. AFAIK these modules require Template Data Provider to send variables to view files, which didn't suit to me.

Mine is much cleaner, there's a $view variable to which you can add variables to pass to the view (eg. $view->children = $pages->find(...)). This is a global variable so it's accessible from every template file, and works with wireRenderFile too. The latter was the reason to create a module of it :)

Even with Template Engine Factory, your template/view files may need to be adjusted if you change the engine as their syntax is not the same.

Link to comment
Share on other sites

There's already the module Template Engine Factory which is similar to your concept. And there's also Latte engine for that. AFAIK these modules require Template Data Provider to send variables to view files, which didn't suit to me.

No, they don't need Template Data Provider for any reason, those modules are not related. In fact, the template factory works the same as the description of your implementation. You also have a $view API variable available, which connects you to the template engine (Twig, Smarty, Jade at the moment). 

Even with Template Engine Factory, your template/view files may need to be adjusted if you change the engine as their syntax is not the same.

The controller logic stays the same, because the module abstracts this in a way that it's the same for any supported template engine. But as you said, the syntax of your "views" is different depending on the template engine. Latte and Twig don't use the same syntax, so you'd need to adjust that. That being said, I think it's uncommon to switch the template engine during a project ;)

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...