Jump to content

Use textformatter in template


Torsten Baldes
 Share

Recommended Posts

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;
 
  • Like 6
Link to comment
Share on other sites

  • 8 months later...

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

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);
  • Like 1
Link to comment
Share on other sites

  • 6 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...