justb3a Posted March 10, 2017 Posted March 10, 2017 ProcessWire Twig Extensions Allows customizing twig, e.g. add extensions. Dependencies: TemplateEngineFactory TemplateEngineTwig Instructions: After installation go to module settings and enable/disable the required extensions/functions. Includes: Twig Extensions Repository Usage: Adds the following extensions/functions: Debug // only if debug mode is turned on {# dump - dumps information about a template variable #} {{ dump('Hello World!') }} string(12) "Hello World!" Intl {# localizeddate - format dates into a localized string representating the date #} {{ "now"|date_modify("-2 day")|localizeddate('medium', 'none', 'en') }} Mar 8, 2017 {# localizednumber - format numbers into a localized string representating the number #} {{ '50.5555'|localizednumber('decimal', 'default', 'en') }} 50.556 {# localizedcurrency - format a currency value into a localized string #} {{ '50.5555'|localizedcurrency('EUR', 'en') }} €50.56 Text {# truncate - cut off a string after limit is reached #} {{ 'Hello World!'|truncate(5) }} Hello... {# wordwrap - split your text in lines with equal length #} {{ 'Hello World!'|wordwrap(4) }} Hell o Wo rld! Array {# shuffle - randomize an array #} {{ [ 'one', 'two', 'three', 'four' ]|shuffle }} [ 'two', 'three', 'one', 'four' ] Date {# time_diff - difference between two dates #} {% set start = "now"|date_modify("-2 day") %} {% set end = "now"|date_modify("+2 day") %} {{ start|time_diff }} 2 days ago {{ start|time_diff(end) }} 4 days ago 4
cstevensjr Posted March 10, 2017 Posted March 10, 2017 @justb3a, I see you are extra busy today releasing new modules. Great work! 1
gmclelland Posted March 20, 2018 Posted March 20, 2018 Hi @justb3a, I just noticed when I upgraded to the latest version of TemplateEngineTwig that I'm now getting an error message. I think the TwigExtensions vendor library might possibly need to be upgraded in this module as well. On https://github.com/twigphp/Twig-extensions it say's it is up to 1.5.1. This module includes 1.3. TemplateEngineTwig upgraded Twig from 1.24.2 to 1.35 I just manually tried to "composer update" in the TwigExtensions module directory, but now I get a different error: Do you have any ideas as to why I'm getting these errors?
gmclelland Posted March 25, 2018 Posted March 25, 2018 Also another thing I noticed is that as of Twig 1.5 debug extension is replaced by Twig's dump function. https://github.com/twigphp/Twig-extensions/commit/5807439c9924323e202c728ceb3199635f09c7e6
V7dev Posted April 17, 2018 Posted April 17, 2018 This is not working for me! I'm using the following: Template Engine Factory 1.1.3 Template Engine Twig 1.1.0 I get this error: User Error Exception: An exception has been thrown during the compilation of a template ("Object of class Twig_Source could not be converted to string") in {}. (in C:\MAMP\htdocs\twig\site\assets\cache\FileCompiler\site\modules\TemplateEngineTwig\TemplateEngineTwig.module line 94) Since I'm new to PW, I'm afraid I can't be much help!
gmclelland Posted April 24, 2018 Posted April 24, 2018 @V7dev - Twig Extensions module seems to work fine with Template Engine Factory 1.1.3 and Template Engine Twig 1.0.4 Hopefully @justb3a can take a look some time soon to see why it's not working with Template Engine Twig 1.1.0? I'm still trying to figure it out, but I'm not making much progress.
V7dev Posted April 24, 2018 Posted April 24, 2018 @gmclelland - That's odd, I just installed a fresh copy of TE Factory and TE Twig with the latest Twig Extensions and I get an internal server error; I disable the Twig Extensions, the site works fine - not sure how I could have messed up such a simple procedure, but I wouldn't put it past me!
gmclelland Posted April 24, 2018 Posted April 24, 2018 @V7dev make sure you're using the versions I specified above. If you use all the latest versions of the modules, you will run into the errors.
V7dev Posted April 25, 2018 Posted April 25, 2018 @gmclelland I overlooked the version numbers, thank you!
gmclelland Posted April 26, 2018 Posted April 26, 2018 @justb3a I was able to fix this module to work with the latest version of TemplateEngineTwig by modifying TwigExtensions/composer.json to: { "require": { "twig/extensions": "~1.5", "twig/twig": "~1.35" } } and then run composer update. Twig also gets installed when composer install is ran because it is a dependency of Twig Extensions Library. So anytime the TemplateEngineTwig module updates it's version of Twig, this module will also need it's version to match. Here's the pull request. https://github.com/justb3a/processwire-twigextensions/pull/11 I think we also should remove the debug extension. That's included in the TemplateEngineTwig module now. See https://github.com/wanze/TemplateEngineTwig/commit/776d3d8b3cf2fd04ea584d92fdc33e214468996b#diff-174a5e0bac30f021aa66bb8899550f87R55 I'll try to create a pull request for this fix as well. Hope that helps!
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