teppo Posted December 26, 2019 Share Posted December 26, 2019 Hey folks! I've been thinking of adding templating engine support for Wireframe, preferably in a way that supports multiple templating engines (module per engine, or some other way to set up the preferred engine), but realise that I don't really have the foggiest which engines folks prefer these days. I'm sure some of you are way more knowledgeable than me in this regard, so I'd lie to ask for your suggestions and/or opinions first ? My current list looks like this – loosely ordered by how much weight I'm thinking it should have: Blade (part of Laravel – standalone from https://github.com/jenssegers/blade) Twig (https://twig.symfony.com/) Latte (https://latte.nette.org/) (Dust PHP) * Anything I'm missing? What about the order, does it make sense? ? * Dust lingers on the list mainly because it's the last templating language I've used. It's a JS thingy ported to PHP, not very popular as far as I know, and not very well maintained, so not sure if it's really worth the trouble. 1 Link to comment Share on other sites More sharing options...
gebeer Posted December 27, 2019 Share Posted December 27, 2019 Nice idea. If you have sth like template engine factory module in mind, people could add their own engine modules. Two more engines, that are quite popular and not on your list: Mustache and Smarty. 1 Link to comment Share on other sites More sharing options...
MoritzLost Posted December 27, 2019 Share Posted December 27, 2019 Twig would definitely be number one on my list, I've been using it for every project for a while and it feels waaaay cleaner than native PHP or Blades. See my tutorials (part one - part two) regarding the Twig integration ? Part two has some examples of connecting Twig to the ProcessWire API, it's a natural fit. 2 Link to comment Share on other sites More sharing options...
szabesz Posted December 27, 2019 Share Posted December 27, 2019 (edited) What keeps me trying out Wireframe is the lack of templating support, so I would welcome this addition for sure. Currently, I do not use any templating engine for PHP so I cannot recommend based on experience, but would like to raise my points of view on this: Twig 3.x: needs at least PHP 7.2.0 to run Blade: PHP >= 7.1.3 Latte: v2.5 requires PHP 7.1 (supports 7.4). v2.4 requires PHP 5.4 (supports 7.4 too). What I prefer is not being forced to update PHP too often. In this regard Latte looks like a good choice. Another factor is how solid the development community behind the library is. I would never use something like a "one man show Blade offspring", as even though one can rely on the parent project for years to come, what happens when the developer of the offspring abandons his project? The reason I am still sticking to plain php for templating is that it needs no updating nor maintenance, which is a timesaver in the long run. Regarding others: https://www.dunebook.com/best-php-template-engine/ BTW, have you taken a look at utilizing Markup Regions somehow? Edited December 28, 2019 by szabesz typos 2 Link to comment Share on other sites More sharing options...
Pixrael Posted December 27, 2019 Share Posted December 27, 2019 1 hour ago, szabesz said: BTW, have you taken a look at utilizing Markup Regions somehow? ? Will be great if you can mix Markup Regions with the concept of the "Tags File Compiler" module https://processwire.com/blog/posts/processwire-3.0-alpha-2-and-2.6.22-rc1/#new-module-file-compiler-tags 1 Link to comment Share on other sites More sharing options...
dotnetic Posted December 28, 2019 Share Posted December 28, 2019 I would go with Smarty or Twig. Used both. Smarty allows to use PHP functions in it's template strings, Twig does not (only with custom extensions), and Twig throws errors if something is not programmed 100% clean. That nagged me about it, also disliked the double delimiters. In terms of speed Twig and Smarty are almost even, sometimes Smarty is quicker, sometimes Twig. 1 Link to comment Share on other sites More sharing options...
teppo Posted December 28, 2019 Author Share Posted December 28, 2019 On 12/27/2019 at 11:29 AM, gebeer said: Nice idea. If you have sth like template engine factory module in mind, people could add their own engine modules. Two more engines, that are quite popular and not on your list: Mustache and Smarty. I'm definitely interested in "modularizing" this part, or alternatively adding support in some other easy-to-enable way. Modules would be a logical solution, but on the other hand it could be even nicer if there was a way (perhaps via Composer) to skip the module part, install the engine, and be done with it. Might be too much to ask, but who knows, maybe I could still make it work out of the box for a couple of popular engines or something ? 13 hours ago, Jens Martsch - dotnetic said: I would go with Smarty or Twig. Used both. Smarty allows to use PHP functions in it's template strings, Twig does not (only with custom extensions), and Twig throws errors if something is not programmed 100% clean. That nagged me about it, also disliked the double delimiters. In terms of speed Twig and Smarty are almost even, sometimes Smarty is quicker, sometimes Twig. I had a quick read about Smarty before posting here, and my initial impression was that it was somewhat obsolete – though now that I've actually checked out their site, it seems that it's at least receiving regular updates, so perhaps that text was a bit opinionated (what a shocker – someone on the Internet might not have been objective ?♂️) They mentioned Smarty being slower these days (apparently it used to be categorically faster than Twig or something), and also talked about it "not being secure by default" (which, I assume, was referring to not automatically escaping content). Not sure how much of those is really true either. I must admit that right now I'm inclined to favour Twig, though, even if for the reason that – in my opinion – a templating language that allows PHP kind of misses the point. I get why one might want to do that, but the way I see it, that eliminates a couple of major reasons to use a templating language in the first place... and suggests that perhaps PHP might've been a better choice in the first place ? On 12/27/2019 at 1:26 PM, MoritzLost said: Twig would definitely be number one on my list, I've been using it for every project for a while and it feels waaaay cleaner than native PHP or Blades. See my tutorials (part one - part two) regarding the Twig integration ? Part two has some examples of connecting Twig to the ProcessWire API, it's a natural fit. Back in the days I wrote a blog post comparing PHP and Twig, but let's not go there now – opinions and all that ? I'll definitely take a closer look at your tutorials, thanks for reminding me of these! And yes, I do think that Twig support would make sense. Honestly the main reason I've included Blade at the top of my list is the Laravel connection: if Blade support could make it easier for someone to move from Laravel to ProcessWire, that'd be a nice little bonus ? On 12/27/2019 at 9:28 PM, szabesz said: Twig 3.x: needs at least PHP 7.2.0 to run Blade: PHP >= 7.1.3 Latte: v2.5 requires PHP 7.1 (supports 7.4). v2.4 requires PHP 5.4 (supports 7.4 too). What I prefer is not being forced to update PHP too often. In this regard Latte looks like a good choice. Another factor is how solid the development community behind the library is. I would never use something like a "one man show Blade offspring", as even though one can rely on the parent project for years to come, what happens when the developer of the offspring abandons his project? BTW, have you taken a look at utilizing Markup Regions somehow? I can definitely see your point. Wireframe itself currently requires PHP 7.1, and officially I've recommended going with one of the supported PHP versions, which at the moment means at least 7.2. PHP 7.1 was EOL'd at the beginning of December, so technically using it is no longer recommended (although if it came with a supported Linux distro, it might still be receiving security updates.) As such, I don't think that any of these frameworks is really going too fast – but I do appreciate your point of view and the info you've dug out (I had no idea which versions were supported) ? You're also right in that it's problematic if the engine isn't well supported. The problem with Blade is that I'd like to support it (due to the Laravel connection), but the official releases are not standalone. As such, it would have to be one of the "unofficial" spin-offs, which I'll admit is not an ideal situation. I've experienced this first hand in the past (with Dust). Twig and Latte definitely have the upper hand here. On 12/27/2019 at 9:28 PM, szabesz said: BTW, have you taken a look at utilizing Markup Regions somehow? On 12/27/2019 at 10:35 PM, Pixrael said: ? Will be great if you can mix Markup Regions with the concept of the "Tags File Compiler" module https://processwire.com/blog/posts/processwire-3.0-alpha-2-and-2.6.22-rc1/#new-module-file-compiler-tags Markup Regions is on my todo list, but I can honestly say that I haven't given it much thought yet. I can see how that would make certain things easier, but I'm also afraid that it'll make it very, very hard to figure out what's going on – mixing Wireframe concepts (layouts, placeholders, partials, and components in particular) with markup regions seems like it could be powerful, but there's a truckload of confusion ahead if one dares to dive too deep into that particular rabbits hole ? Thanks everyone for your comments so far! At the moment I'm leaning towards Twig as the first experiment, then Latte (if all goes well), and finally Blade. Unless some new information shows up, that is. Apparently there haven't been that many major changes in this field lately – I used Twig with some Zend Framework projects back in the days, and by the looks of it it's still going strong ? 4 Link to comment Share on other sites More sharing options...
Recommended Posts