Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank defaults aren't working #6

Closed
stevenirby opened this issue Feb 23, 2024 · 3 comments
Closed

Blank defaults aren't working #6

stevenirby opened this issue Feb 23, 2024 · 3 comments

Comments

@stevenirby
Copy link

Amazing work with this CMS! It's very fast and slick.

One issue I ran into is, my site expects blank values in the yam file:

  - name: Cara Fischer
    nation: ''
    life: ''
    image: ''
    learn_more_urls: null
    bio: ''
    fun_fact: ''
    quotes: null

In the page settings I put a blank string for the defaults:

        fields:
        - name: name
          label: Name
          type: string
          required: true
        - name: nation
          label: Nationality
          type: string
          default: ''
        - name: life
          label: Life Span
          type: string
          default: ''
        - name: image
          label: Profile Image
          type: image
        - name: learn_more_urls
          default: ''
          label: Learn More URLs
          type: string
          list: true
        - name: bio
          label: Biography
          type: rich-text
          default: ''
        - name: fun_fact
          label: Fun Fact
          type: text
          default: ''
        - name: quotes
          label: Quotes
          type: string
          list: true
          default: ''
        - name: meta_title
          label: Meta Title
          type: string
          default: ''
        - name: meta_description
          label: Meta Description
          type: text
          default: ''

However, this is saving like this with no fields or defaults:

  - name: Cara Fischer

Is this expected? Is it possible to have the fields populate?

@hunvreus
Copy link
Member

Right now, I sanitize the entire object before saving it. If you have an empty string it gets removed from the object altogether.

Can you help me understand why you need to save empty/falsy attributes in your frontmatter? Do you leverage that in any particular way in your website?

@stevenirby
Copy link
Author

To be blunt because there's a lot of bad code that does stuff like this:

{{ $artists := where $.Site.Data.artists.artists "name" $term }}
{{- range $artists -}}
    {{- $countryData := (index $.Site.Data.countries .nation) -}}
{{- end -}}

Which expects a value to be there. Yeah, definitely, the code should be more defensive and do a check that .nation exists.

@hunvreus
Copy link
Member

I don't think I'm going to change this approach for now. A lot of my code currently expects the objects to be sanitized when they're loaded in the editor. Closing for now but I will consider it if I see the request popping up again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants