Jump to content

Recommended Posts

Posted

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!

Posted

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
  • 8 months later...
Posted

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;
Posted

The txtfirmatter doesn't return but modify the variable instance. No need to $new = ...

See ,xamples in this thread marked as solved.

  • Like 1
Posted

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
  • 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
×
×
  • Create New...