Jump to content

Prevent output formatting inside method of fieldtype/inputfield


Recommended Posts

Hello @ all,

Lets imagine I have a value stored in the database which I can output on the frontend with a simple API call like


and this value will be manipulated with the formatValue() method before output on the frontend. So it was stored in the database like this:

This is my value

And after running through formatValue() method it will be:

<p>This is my value.</p>


So far so good.

Now I have created a method inside my fieldtype/inputfield class which uses this value:

public function myMethod()
	$value = $this->myValue
	//value should be unformatted as dirctly stored in the database



myValue is always formatted  because it runs through the formatValue method first - is there a way to get the "raw" data instead without setting ouputformatting to false inside the template if I call

echo $page->myValue->myMethod();

I think it would not be possible because myMethod() is part of  myValue, but maybe someone has an idea how it could work.

Thanks in advance

Link to comment
Share on other sites

Thanks @LostKobrakai,

but this was a misunderstanding.

I wanted to prevent the usage of getUnformatted or page->of(false) or something like that method inside the template. I was looking for a possiblitiy to disable outputformatting inside the method itself, so I can use the API without adding a getUnformatted on the template base.

But it doesnt matter, because it was a thinking mistake of mine. I dont need the unformatted value from the db - i need the value from the db in a specific format and therefore I am using a manipulation function to get the desired result.

But it would be interesting if disabling the formatting inside a method itself is possible.

Link to comment
Share on other sites

@Juergen You can disable formatting from anywhere, why not use $this->of(false) inside your method? If you're worried about changing the output formatting setting unexpectedly, you can save the current setting first and then restore it after you've received the unformatted value or done whatever you want inside your method.

$of = $this->of();

// custom code here ...


Or is this still not what you intended?

  • Thanks 1
Link to comment
Share on other sites

Hello @MoritzLost

This is what I wanted, but

13 minutes ago, MoritzLost said:

why not use $this->of(false) inside your method?

leads to an internal server error on the frontend. In only know


There is a similar post in the forum, which does not work as expected too.

Thanks for your hint.

Link to comment
Share on other sites

Hm, I thought that method was available in a fieldtype context as well ? Maybe you can access the page context from within your method? Really not sure. Though from within the fieldtype you should definitely have access to the raw value, so the method should be able to return whatever you want ...

Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...