JSAPI: Edit bodycopy div content


(Rhaggith) #1

Hi all,

 

Just wondering if there's a way to edit the content of a standard page asset using jsapi? I couldn't find anything to date in the forums...

 

It doesn't say anything outright, but it's implied in the manual that maybe you change a 'html' attribute, but I get 'attribute doesn't exist' errors bouncing back at me. I've tried the html attribute on the standard page asset, and I've tried grabbing child bodycopies to do the same... no luck.

 

Anyone had any experience doing something similar?

 

Thanks,

R

 


(Anthony Barnes) #2

The Edit+ interface achieves this with a combination of JS API requests (for bodycopy div management) and manually crafted POST requests to /_edit to save content changes. The JS API is a newer feature (relatively) and it doesn't map all the underlying functionality required to properly change the content of a standard page, which can be far more complex  than just setting some HTML.

 

If you wanted to construct one of these POST requests yourself you could open development tools (e.g. chrome/firebug) inside the Edit+ interface a inspect the ones that it sends when you save a page. Fair warning though, it isn't trivial.


(Rhaggith) #3

Thanks Anthony, makes sense. I'll have a look at the post requests and try not to set myself on fire :)


(Bart Banda) #4

The other complexity is that a standard page asset is made up of separate content container assets, so you really want to be saving the contents of each content container and interacting with them instead of the parent standard page asset. I haven't tried it before, but maybe you could try and use the setAttribute function to save the HTML of the content container asset that is part of the standard page?


(Rhaggith) #5

Thanks Bart, I'll take another look - I had thought I went through standard page, then bodycopy, bodycopy_div, then content asset to set the html attribute with no joy. I did it pretty ad hoc, but with my fuzzy brain I can't be totally certain. 

 

It's just an idea I have for some clients who expressed wanting to GIT their content, some of it being a fair amount.

 

At the moment, just using form submits, I'm kind of looking at something like;

 

- if asset id doesnt exist, create asset, else getassetinfo

- get asset_id, link_id of bodycopy_div (need for next step, assume there's only one div?)

- set asset bodycopy div to raw_html, raw_html (sent via formdata.* to ???... var = bodycopy_saved[bodycopy_<bodycopy_assetid>][<bodycopy_div_assetid>] )

- on callback,

      - set bodycopy div content to given html (sent via formdata.* to ???... var = bodycopy_<bodycopy_assetid>_content_type_<content_string>_<link_id>_html )

 

All just thoughts at the moment, no code.


(Rhaggith) #6

Cheers Bart, went down that extra container level and updating the html attribute works.

 

Squeeeeeeeeeeeeeeeeeee!


(Rhaggith) #7

So, I've run into a snag.

 

I'm trying to paste raw html code in to a raw html div, and setting the html attribute appears to do a htmlspecialchars or something... it's converting

<!-- ---> 

to

&lt;!-- ---&gt;

Which isn't ideal  :(

 

Am I doing something wrong or is this expected of the html attribute?


(Anthony Barnes) #8

By default (with the 'filter front end input' setting enabled) matrix will escape content coming in from the 'front end' - which includes forms and the JS API. I was having a conversation offline with Bart and trying to dig through the memory banks to figure out why I'd written the Edit+ code to use manual POST params to the _edit url of the page and I think you've encountered it. It's not viable (or even desirable) for most to simply disable the setting since it can open you up to XSS.

 

Using _edit urls requires you to have a valid login session and user type so isn't included in the 'filter front end input' configuration.

 

I've been out of active development for Edit+ for quite a while now so there might be an alternative I don't yet know about.