Update Page custom attribute value from a block

Permalink
Hello,

Can anyone help, I have been finding it hard to work out how to update a page attribute from a block.

Regards

Adam

 
jordanlev replied on at Permalink Reply
jordanlev
Can you explain in more detail what you're trying to do? Do you want the attribute to be changed from the add/edit dialog of the block (so only by admins), or from the front-end view of the block (so by all users of the site)?

What is the attribute you're trying to change?

-Jordan
ambates replied on at Permalink Reply
I am trying to update a custom page value through a block.

So the page will have one block which when updated will update the content on the page, then the outputted HTML will put into a HTML custom field which can then be used when using the page list block.
meir replied on at Permalink Reply
Hi,

I have the same issue. Did you figure out how to do it?

Thanks
loeppel replied on at Permalink Reply
Same Issue here. Tried it with just calling
Page::setAttribute('key', value);
but semms thats not that easy.

Any hints?
jordanlev replied on at Permalink Reply
jordanlev
Try this:
Page::getCurrentPage()->setAttribute('key', value);
loeppel replied on at Permalink Reply
Solved:

public function save($data) { 
            $p = Page::getCurrentPage();
            if(is_object($p)) {
              $p->setAttribute(CollectionAttributeKey::getByHandle('handle'), $data['key']);
          }
}


I think the important part is to get the Handle! The API implies you can use the handle direclty, but, in my case, it's not true.