Contentful support

Hi team,

I would like to be able to use Contentful for my site, or GraphCMS. Mainly use headless CMS to be able to host it on Vercel or Netlify.

Thanks a lot !
Philippe

2 Likes

Hi Philippe!

I’d love to see headless CMS support as well. I make JSON API endpoints using CouchCMS (similar to Contentful). If Blocs were able to use fetched JSON as a data source, that would open a lot of doors to CMS’s.

For instance, grabbing dynamic content such as a profile name: Data > source > json_response.user.name

Even more useful would be if there was a way within Blocs to loop over fetched JSON arrays to render repeatable content (like image galleries or blogs posts). As of now, I achieve this by exporting the project and then tinkering with the code afterward, but it would be more ideal to have Blocs export the fetch request and rendering code itself so it wouldn’t be overwritten after each project export.

Maybe supporting universal fetch requests and raw JSON would be easier to implement than any particular CMS. :hand_with_index_finger_and_thumb_crossed:

Matthew

1 Like

I’m looping a fetched JSON array to create a gallery on a site. I’m just using the code widget to achieve it.

3 Likes

Excellent! Sorry, I should have mentioned that I’m new here and might have overlooked something.

I do see the custom code widget and have managed to loop over some fetched JSON using Vue! :raised_hands: I’m only able to preview the fetched content via the play button (not “live” in the app), and I assume that’s normal.

@PeteSharp, do you ever use fetched JSON in non-code-widget areas? Such as a parralax background of a hero bloc? I know, with IDs and a little DOM traversal, I can swap out the background with JS in a subsequent code widget, but I wonder if there’s a more elegant solution.

Thanks for the help!

Yes. JavaScript doesn’t run on the canvas for safety reasons. Make sure you disable preview on the code widget too.

You can of course you page header and footer also or attach files.

Pretty much the way I would do it with Blocs.

In my case I am using JavaScript to populate a div with an ID and the script has markup.

1 Like

Hi guys,

Great, I’ll give a try with CouchCMS.
If working well for you, could you please share the code snippet you used ? (without API endpoint, private keys and co of course :slight_smile: )

Regarding security point of view, my understanding is that the endpoint will be publicly visible in source code, including public key at least, or private key at worst.
This could lead to an unsupervised usage of the API.
Any idea on how to handle this ?

Thanks
Philippe

In one example. Im just using the YouTube API and following its documentation. Im using that to populate a gallery of thumbnails and to play the videos.

1 Like

You could use PHP. I haven’t done it and maybe Jannis (@Jannis) can head you in the right direction. But I believe PHP has a decoder for JSON??

2 Likes

https://www.php.net/manual/en/function.json-decode.php

3 Likes