Torsten Baldes Posted February 17, 2014 Share Posted February 17, 2014 hi there, is it possible to use a textformatter on a string/field in the template without applying it to an inputfield in the field settings? i searched the forum but didn't found any solution … thanks! Link to comment Share on other sites More sharing options...
Soma Posted February 17, 2014 Share Posted February 17, 2014 You just get the textformatter module and use the formatValue(). It accepts Page, Field, String but you can also pass an empty page and field as most textformatters also don't use it except HannaCode I think. $str = $page->textfield; $modules->TextformatterModuleName->formatValue(new Page(), new Field(), $str); echo $str; This is deprecated, but should work for most textformatters still $str = $page->textfield; $modules->TextformatterModuleName->format($str); echo $str; 6 Link to comment Share on other sites More sharing options...
Torsten Baldes Posted February 18, 2014 Author Share Posted February 18, 2014 Thanks! Works like a charm! Link to comment Share on other sites More sharing options...
pwFoo Posted October 27, 2014 Share Posted October 27, 2014 Hi, searched for that topic because I try to load the textformatter modules like above- But I need to get the textformatters from the page field first. Tried this, but doesn't work. foreach ($field->textformatters as $textformatters) ... A dump of $field->textformatters is empty.How could I get the textformatters? *Update* I try to format a $field->value like this. $f = $modules->get('TextformatterTextile'); $text = $field->value; $new = $f->formatValue(new Page(), new Field(), $text); // $new is empty! echo $new; $field->value = $new; Link to comment Share on other sites More sharing options...
Soma Posted October 28, 2014 Share Posted October 28, 2014 The txtfirmatter doesn't return but modify the variable instance. No need to $new = ... See ,xamples in this thread marked as solved. 1 Link to comment Share on other sites More sharing options...
pwFoo Posted October 28, 2014 Share Posted October 28, 2014 Thanks... was too simple... Link to comment Share on other sites More sharing options...
Soma Posted October 28, 2014 Share Posted October 28, 2014 Hi, searched for that topic because I try to load the textformatter modules like above- But I need to get the textformatters from the page field first. Tried this, but doesn't work. foreach ($field->textformatters as $textformatters) ... A dump of $field->textformatters is empty.How could I get the textformatters? Via the field print_r($fields->body->textformatters); 1 Link to comment Share on other sites More sharing options...
tb76 Posted January 15, 2021 Share Posted January 15, 2021 With Hanna Code (TextformatterHannaCode) it works like this: $hanna = $modules->get('TextformatterHannaCode'); $page->body = $hanna->render($page->body); see: https://processwire.com/modules/process-hanna-code/ 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