Question - How to update Slice model.json from local to Prismic?

I'm testing Nuxt.js with Prismic Slice machine and if i modify the model.json file from the slice, the changes are not updated in the Prismic page designer.
This is correct?
or i have tu run a command to update and synchronize my local Slices ?

1 Like

That's right as far as I am aware, but I heard they are working on improving how it works as it is still in beta. I think they need to be think carefully about how it interacts.

What I plan to do is make a library of slices and then import them at the start of a project, although I haven't tried this yet.

Unfortunately, after the initial setup that I think (for the time being) we will have to do it the old fashion way of keeping everything in a big json file ready to copy and paste.

Edit: Doesn't seem to allow you to use any other libraries than the ones registered/uploaded to Prismic. Shame, while I want to contribute I am not ready for it to be public.

Hey Guys, (Welcome to the community David!)

This is something we’ve already begun work on, a Custom Types API! With this you can send you custom types to the repo with a CURL request.

Though I’m not 100% how it functions on the slice level, hopefully the team will help clarify this for me.

I’ll get some documentation out very soon on how this works currently, I’ll keep you updated here once that is done.

Thanks.

1 Like

@jjames.home @Phil Thanks! , well , i’ll be waiting an update on this, this project seems amazing and I know that in the future it will be more.

Hey @djesus1906.96 Can you give me a better understanding on why you prefer updating your model through the code and not from the interface ?

We were planning to start synchronizing from the interface to the code but maybe we are wrong on that ? If we start with that. Will it solve your issue ?

Hi Renaud, for me it is five reasons:

  1. Version control. When I make a change in the component I can easily change the content model at the same time and it will be version controlled
  2. I already keep the content model saved in the root of my repo named template.json and menu.json
  3. Copying the same content model to 10 page types is laborious
  4. General organisation where a content model can be kept with the component as with the Slice Machine component generation
  5. Faster custom provisioning. I could setup a Prismic repo with my own custom content model much faster.

I do like that I am able to modify it via the interface, initially I was afraid that clients would accidentally modify it but this hasn’t been the case. Maybe a sync from the code command in the CLI is possible?

Personally, I don’t see the usefulness of syncing from interface to code. Most of the people who modify the content model will be developers who have access to the codebase. Although it would be beneficial to have any form of sync option I would like to hear a point to the contrary.

@djesus1906.96 What about you?

1 Like

We definitely want to add a sync command to the CLI. But whether it syncs things up, down or a mix of both is a tough question for me. A point against solely syncing models from code is that at the moment, the interface is the easiest way to write valid data models. From experience, it’s ok to update an existing field from code, but writing things like items and repeatable zones in JSON (and from scratch) is too unfriendly.

That being said, syncing from code is the way to go. And my take on it is let’s drop JSON: each component should export a model prop type that gets parsed by the CLI on sync. Pretty much what https://blocks-ui.com/docs/controls does. The model could be stripped down from fields related to the editor (placeholders, etc.).

So, pretty much like this in Vue:

<script>
export const model = {
  title: PrismicRichText,
  icon: PrismicImage,
  items: [/*...*/]
}
export default {
  name: 'MySlice'
}
</script>

I can see tons of utility with this being implemented, auto mocking and provisioning for example. Syncing things from the API to your project would be super helpful in some cases though, like bootstrapping a slices library from an existing Prismic project.

@jjames.home I believe the easiest way to write your custom library right now is to use the --create-slice command and then manually update each slice in the interface. Once we sort things out, we’ll make sure you can update all your models in 1 command :blush:

1 Like

I can see why it is a tough decision and you are right to consider it carefully.

I really like the UI blocks idea… That would make my apps be much more robust and pain free.

When I started to use Prismic being able to modify the JSON directly in the CMS was definitely a boon and I can see the benefit from syncing from the API to the project, however in my personal experience when I provision a project it would be completely from the CLI/project side so I don’t have to go back and forth:

  1. Activate the CLI
  2. Provision the repo from the CLI
  3. Reference self-hosted library via the CLI (maybe have an option to use a json file with appropriate references). Clients are always asking how to use the slices and if I have my own library I can add Storybook to said library of standardised slices but it was quite challenging to maintain when I did attempt it
  4. Everything is synced up to the Prismic repo

It would be really, really amazing if we could do this. I could setup a standardised GitHub template to have a basic app ready for the Prismic CLI.

I actually did use --create-slice initially but I ended up just copying slices that I had modified from the SM to conform to my own slice structure.

Thanks for the hard work and keep it up! :grinning:

Just wanted to add a big benefit to me that SM has added. My production generate was really verbose and obtuse. SM seems to deal with it for me and so easily.

1 Like

@jjames.home thanks for the very interesting feedback
@alws created an RFC here https://github.com/prismicio/slice-machine/issues/8
Let’s move the discussion there.

2 Likes

This issue has been closed due to inactivity.