CloudCannon / bookshop

📚 A component development workflow for static websites.
MIT License
248 stars 21 forks source link

_live_render does not work in props in toml file #101

Open silveltman opened 2 years ago

silveltman commented 2 years ago

When setting live_render: false in the component itself it does work. When setting _live_render = false in the props in the .toml file, it does not work.

bglw commented 2 years ago

👋 Setting _live_render = false in the props will affect new components, as that key will be added when the component is created.

We don't yet have an automated way of updating existing structures on the site, so if the component already exists you will need to add the _live_render key to its front matter.

If that is what you're doing and it still isn't working let me know and I can dig into it further.

a-luttringer commented 2 years ago

@bglw - I have a similar issue, tried a lot of different variations to make _live_render or {{ if site.Params.env_bookshop_live }} work but nada.

I have my layout:

{{ define "main" }}
{{ partial "bookshop_bindings" `.Params.content_blocks` }}
{{ partial "bookshop_partial" (slice "page" .Params.content_blocks)}}
{{ end }}

My font matter:

- _bookshop_name: component-name-1
    _live_render: false
    title: Lorem

My component:

spec:
  structures:
    - content_blocks
  label: 'Component Name 1
  description: ''
  icon: ''
  tags: []

blueprint:
  _live_render: false
  title: Lorem

What am I doing wrong? Tested all kind of variations (with/without "_", new/old components etc.)

bglw commented 2 years ago

@a-luttringer my apologies, this is probably on me for not making the documentation clear enough (better docs are in the works!)

The important note is the following:

This setting will only apply if the component is rendered directly from a site layout. If this component is within another component, it will still update live (as the parent re-rendering will encapsulate it).

That is, in your code samples above: the component-name-1 component is flagged to not live render — however the higher level page component does still live render, and live rendering it necessitates rendering the component-name-1 contained within. _live_render as it stands only affects tags that are used directly in your layout.

This is a limitation I'd love to solve, and I have had some ideas floating around for the concept of "freezing" components such that it behaves in the way you're expecting it to (which I acknowledge would be more intuitive).

For now, the best path forward is to instead handle the live editing environment within your component with site.Params.env_bookshop_live and render fallback content.

(Out of interest, what is your current use case for wanting to disable the live rendering? I'm also hoping to improve the Hugo support across the board such that this workaround is needed less, so it's nice to hear what specific features are missing 🙂)