porl Posted February 15, 2016 Share Posted February 15, 2016 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 More sharing options...
pwired Posted February 15, 2016 Share Posted February 15, 2016 http://modules.processwire.com/modules/template-engine-factory/ Link to comment Share on other sites More sharing options...
teppo Posted February 15, 2016 Share Posted February 15, 2016 @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 More sharing options...
porl Posted February 15, 2016 Author Share Posted February 15, 2016 So Template Engine Factory still works fine with 3.x then? If so I guess it's my best bet. Link to comment Share on other sites More sharing options...
tpr Posted February 15, 2016 Share Posted February 15, 2016 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. 2 Link to comment Share on other sites More sharing options...
porl Posted February 15, 2016 Author Share Posted February 15, 2016 Sounds great! I've been out of the web game for a bit so didn't see Latte before, but it looks interesting. Definitely keen to see it when you share it! Link to comment Share on other sites More sharing options...
tpr Posted February 15, 2016 Share Posted February 15, 2016 Latte is not that popular as Twig or others so it's not a surprise It's a great template engine though imo. 1 Link to comment Share on other sites More sharing options...
porl Posted February 15, 2016 Author Share Posted February 15, 2016 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 More sharing options...
tpr Posted February 15, 2016 Share Posted February 15, 2016 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 More sharing options...
Wanze Posted February 15, 2016 Share Posted February 15, 2016 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 1 Link to comment Share on other sites More sharing options...
tpr Posted February 15, 2016 Share Posted February 15, 2016 Thanks, seems like I've missed the key point in TEF or simply messing it up with another module 1 Link to comment Share on other sites More sharing options...
porl Posted February 16, 2016 Author Share Posted February 16, 2016 An update for anyone reading - the Template Engine Factory (along with the Twig module for it) seems to work perfectly in 3.x. Thanks for the suggestions! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now