Jump to content

Recommended Posts

Posted

Hi,

I have this situation I'm working on my template file and $page is what I want.. But I just want to add one field to it. And there is more.. I don't want to save it. So I just want to add new $field to my $page object virtually. After this I'm going to change it to JSON and print it out.

Is this possible? If yes, please share the answer :)

Thanks!

Posted

If the field your settings a value for is not reserved or found in the templates fields it's just added to the object as runtime property.  

$page->notAAssingedField = "Hello";

echo $page->notAAssingedField; // outputs: Hello

If you'd need more specific additions you could also use hooks to extend the page object or even make a own object, extending the existing page object. This new object can then be assinged to specific templates in the backend. 

Edit:

As you've said you'll export it to JSON: A page object has lots of properties, which I don't know if you need all of them. So I would suggest taking a look at the json so it's not bloated with stuff you're not using, especially if it's for something like ajax.

  • Like 2
Posted

Do you need this field to be shown in the admin or frontend? Are you just setting a value programatically, or does it require user input?

I see now "in template".

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...