owzim Posted January 12, 2015 Share Posted January 12, 2015 I am converting a current project to twig templates (with data providers of course ) An having the following issue when calling properties on some PW objects like page: in PHP $page->template->name in Twig, that does not work: page.template.name throws: Fatal error: Exception: An exception has been thrown during the rendering of a template ("Method Page::template does not exist or is not callable in this context") This however works: page.get('template').get('name') I guess this has something to do with the fact that those properties are added dynamically (internally stored in the data array/object, and set/get via magic methods) How to fix this? Link to comment Share on other sites More sharing options...
felix Posted January 20, 2015 Share Posted January 20, 2015 I am converting a current project to twig templates (with data providers of course ) Yay: Glad to hear people using this! Sorry for the late reply: Just saw that you've posted - I follow this thread now to get notifications on updates. You're right. Some propertys don't load automatically and you need to "get" them the way you've stated. There currently isn't a "fix" for this as we didn't classified this behaviour as an error. Link to comment Share on other sites More sharing options...
marcus Posted January 20, 2015 Share Posted January 20, 2015 Yay: Glad to hear people using this! ProcessWire Recipes is using this as well 1 Link to comment Share on other sites More sharing options...
tpr Posted July 26, 2015 Share Posted July 26, 2015 An having the following issue when calling properties on some PW objects like page: in PHP $page->template->name in Twig, that does not work: page.template.name throws: Fatal error: Exception: An exception has been thrown during the rendering of a template ("Method Page::template does not exist or is not callable in this context") I'm also facing this (I'm new to Twig in ProcessWire). Of course setting each variable first in the "controller" file, like $view->template, $view->template->name (eg. in "services.php" for services.twig) fixes this, but this overly complicates things (and surely there's a better solution). It's the second time I'm trying my head around Twig but I still can't see the benefits over Latte Link to comment Share on other sites More sharing options...
felix Posted July 27, 2015 Share Posted July 27, 2015 Hi tpr which version of processwire are you using? This should be fixed in 2.6. Are you using TemplateDataProviders, also? The main reasons we are using twig are: Easier to understand for "non techies" (or people coming from other systems like symfony etc.) It's ability to do "recursive" template overwrites via blocks/extend is just plain awesome (if you're interested i can post some examples how we structure our templates) Seperation of concerns: Trying to keep "Business logic" (Getting/Setting Data) away from the views which makes them a lot easier to read and maintain. As a rule of thumb we're only doing basic control structures (if/else) and loops inside our views. Everything else is kept outside of the view, inside the controllers. Syntax hiliting is much better if you get rid of <?php echo '<li><a href="' . $xyz .'... inside your templates Link to comment Share on other sites More sharing options...
tpr Posted July 27, 2015 Share Posted July 27, 2015 I see now how Twig Replace can be used with TemplateDataProviders, thanks! Actually I was using the module TemplateEngineFactory (with PW 2.6) where I got that error, using Twig Replace it is gone. And thanks for the Twig benefits explanation, that's exactly why I'm using Latte What I was try to tell is that I see no real benefits of Twig over Latte. Even with TemplateDataProviders it sounds less convenient (for me, at least). There are some hand html element macros like "n:if", "n:class", "n:inner-foreach", etc, and even PHP can be used in .latte files (if you don't get separation of concerns too strict). Link to comment Share on other sites More sharing options...
Tyssen Posted April 20, 2016 Share Posted April 20, 2016 I'm just trying this out for the first time and wondering how to do the following things in Twig. $modules->isInstalled("AdminLinksInFrontend") ? $modules->get("AdminLinksInFrontend")->render() : ""; <?php echo AIOM::CSS('../../assets/css/style.css'); ?> Also, when trying to do <script>{% include "../../assets/js/fonts.min.js" %}</script> I get Error: Exception: Looks like you try to load a template outside configured directories (../../assets/js/fonts.min.js) in "_layout.php" at line 23. (in /site/modules/processwire-template-twig-replace/Twig-1.18.0/Twig/Loader/Filesystem.php line 235) Is there a place to configure directories? Or another way to allow directory traversal? Link to comment Share on other sites More sharing options...
onjegolders Posted May 23, 2016 Share Posted May 23, 2016 Hi Felix, other Twig users, I realised I posted the below in the wrong thread previously: Would it be possible (in theory at least) to use PW's new Page() functionality whilst still using the Twig module? I've had a fair bit of joy with most of it so far {{ session.redirect('/about') }} for example works great. This was leading me to hope I may be able to use the full power of PW still whilst keeping things clean with Twig. Has anyone managed to do this successfully or would I have to revert to pure PHP to carry out certain PW tasks? Thanks! Link to comment Share on other sites More sharing options...
elabx Posted July 10, 2019 Share Posted July 10, 2019 Hi! Has anyone tested this module with recent ProcessWire versions? 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