plentico / plenti

Static Site Generator with Go backend and Svelte frontend
https://plenti.co
Apache License 2.0
985 stars 50 forks source link

Editable JSON for global data #237

Open notramo opened 1 year ago

notramo commented 1 year ago

Is it possible to edit a JSON using CMS, which contains data that should be available on every page? E.g. html.svelte contains a footer, with information about the company (phone, email, etc). It should be possible to change this from the CMS. It is displayed on every page, so it's not appropriate to put it in content/. Is there an existing feature that can be used to accomplish this?

jimafisk commented 1 year ago

You can create global content that's used on every page, but the downside is currently Plenti will create an endpoint to it until we resolve:

For now though, if you're ok with having routes for your global content, you could:

  1. Create a single content type for company info: plenti new type company_info --single
  2. Add whatever JSON you want to the new content/company_info.json file that was created:
Example content/company_info.json ```json { "name": "ABC Corp", "phone": "555-555-5555", "email": "hi@abc.com" } ```
  1. Pull out the company info in a global template file (like layouts/global/html.svelte) using the magic allContent prop:
Example layouts/global/html.svelte ```svelte {content.filename} {#if user && $user.isAuthenticated} {/if}
{companyInfo.fields.name}
{companyInfo.fields.phone}
```
  1. Then to edit the info, just go to the route that's automatically created for it (http://localhost:3000/company-info) and edit it like any other page
  2. Optional: the page for the above route will be blank unless you add some markup to layouts/content/company_info.svelte

Note: Everything above is pseudo code that I haven't tested, so you might have to correct errors here and there. Just let me know if it gives you trouble!