Forgive me if I’ve fallen for buzzwords, but I’m wondering if anyone has done any work with MODX as a headless CMS.
I’ve been messing around with Astro and have been finding it very easy to get into and get sites built, but the CMS offerings don’t have the good feels that MODX does.
Ideally, I would love to be able to query MODX and get the resources as JSON including template variables and such. Is there an extra that exists for this that I’m just not googling for correctly? Or is this something that can be hand rolled with some effort.
I found this a while back How to set up a restful API for Modx 3 maybe this is what i’m looking for. I had also considered quickapi in the past.
When you only need the content for reading, maybe have a look at this?
Hmmmm, interesting, and then I could access template variables by adding the includeTVs
etc properties?
Yes, maybe you need the processTVs
property also.
1 Like
Is there a way to do it without Fenom? I tried to do a simple output modifier like
<?php
return json_encode($input)
And the apostrophe’s came out kinda goofy.
You could use the REST API.
The problem is, that with the default controller, the content is returned as stored in the database and therefore unparsed. (Meaning the output still contains MODX tags [[...]]
).
You can parse the content in the controller, but you have to call the function yourself.
Also the plugins from other installed extras may not run when using the REST API. An example is an extra that obfuscates all e-mail addresses in the output (on the event OnWebPagePrerender
).
You also would have to adapt the code in the controller to output TVs with the rest of the fields.
Where did you try to use this output modifier?
I ended up scrapping the code but it was something like
[[pdoResources:toJSON?
# params
]]
And it out put something like:
<pre>[{&93;key&91;...</pre>
I had the content type set to JSON and richtext turned off so I don’t know, seems like something is doing a bit too much.
pdoResources has a the option json
for the return property.
[[pdoResources?
&return=`json`
...
]]
So you don’t need an output modifier.
2 Likes