V7dev Posted April 18, 2018 Share Posted April 18, 2018 After some effort and endless searching for articles to lead me in the right direction, I'm stumped. I'm using Twig and have the following installed: ProcessWire 3.0.98 Template Engine Factory 1.1.3 Template Engine Twig 1.1.0 In ready.php, I've added the following code (which works wonderful without Twig) $wire->addHookProperty('Page::summarize', function($event) { $fieldName = $event->arguments(0); if(!$fieldName) throw new WireException("No field provided"); // get max length or use 300 as default if none provided $maxLength = (int) $event->arguments(1); if(!$maxLength) $maxLength = 300; $page = $event->object; $value = $page->get($fieldName); if(!strlen($value)) { // requested value is blank, nothing more to do $event->return = ''; return; } // get beginning of value, without any HTML in it (if any) $value = mb_substr(strip_tags($value), 0, $maxLength); // if output formatting on, make sure value is entity encoded if($page->of()) $value = $event->sanitizer->entities1($value); if(strlen($value) >= $maxLength) { // limit length of returned value between words // by truncating to the last space character $value = substr($value, 0, strrpos($value, ' ')); // append an ellipsis to indicate there is more $value .= '…'; } $event->return = $value; }); In my news.php template file, I have the following: <?php namespace ProcessWire; $results = $page->children("template=news, limit=10, sort=-created"); $view->set("results",$results); And in news.html.twig I use something like this: {{ summarize('result.body', 500) }} Exception: Unknown "summarize" function. (in twig\site\assets\cache\FileCompiler\site\modules\TemplateEngineTwig\TemplateEngineTwig.module line 94) So far Processwire is awesome, I'm loving it! Link to comment Share on other sites More sharing options...
tpr Posted April 19, 2018 Share Posted April 19, 2018 Perhaps a hook priority issue? Search the forum, eg here: https://processwire.com/talk/topic/1983-prioritising-hooks-for-same-event/ 1 Link to comment Share on other sites More sharing options...
gmclelland Posted April 12, 2019 Share Posted April 12, 2019 @V7dev - I know this older, but did you figure it out? Another way you could probably do this via a custom module similar to how it's done in https://github.com/justb3a/processwire-twigextensions. Look at the FileExists Helper in that module. 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