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

Feat: support hidden widget in files collections #3046

Open
chokeul8r opened this issue Jan 7, 2020 · 14 comments
Open

Feat: support hidden widget in files collections #3046

chokeul8r opened this issue Jan 7, 2020 · 14 comments
Labels
area: extensions/widgets pinned type: feature code contributing to the implementation of a feature and/or user facing functionality

Comments

@chokeul8r
Copy link

chokeul8r commented Jan 7, 2020

Repo: chokeul8r/gncms

I am attempting to use NetlifyCMS in a Gatsby Landing Page project for the first time. My problem relates to the config.yml file and Template key field in particular. The template key is not showing up in my frontmatter and/or my graphgl query.

backend:
  name: git-gateway
  branch: master

media_folder: static/assets
public_folder: assets

collections:
  - label: "Pages"
    name: "pages"
    files:
      - label: "Home Page"
        name: "home"
        file: "content/home.md"
        fields:
          - {
              label: "Template Key",
              name: "templateKey",
              widget: "hidden",
              default: "home-page",
            }
          - { label: Background Image, name: backgroundimage, widget: image }
          - { label: Title, name: title, widget: string }
          - { label: Sub-Title, name: subtitle, widget: string }
          - { label: Intro text, name: intro, widget: text }
          - { label: Body text, name: body, widget: text }
          - { label: Profile Image, name: profileimage, widget: image }
      - label: "Thank You Page"
        name: "thank-you"
        file: "content/thank-you.md"
        fields:
          - {
              label: "Template Key",
              name: "templateKey",
              widget: "hidden",
              default: "thank-you-page",
            }
          - { label: Title, name: title, widget: string }
          - { label: Intro text, name: intro, widget: text }
          - { label: Image, name: image, widget: image }
@erezrokah
Copy link
Contributor

Hi @chokeul8r do you mind sharing your repo?

@erezrokah
Copy link
Contributor

Sorry for the late reply, hidden fields are meant to be used on folder collections when creating new items: https://www.netlifycms.org/docs/widgets/hidden/#hidden since they have a pre-defined uneditable value.

@erezrokah
Copy link
Contributor

Changed the title to reflect the underlying issue.

@erezrokah erezrokah changed the title config.yml Template Key not found in markdown and/or graphql query Feat: support hidden widget in files collections Jan 8, 2020
@nettelandways
Copy link

nettelandways commented Mar 18, 2020

I have the exact same issue.

- { label: layout, name: layout, widget: "hidden", default: "my-template-key", }

does not work. It does not show up in the .md file that is produced through the cms

@NikitaVr
Copy link

NikitaVr commented May 6, 2020

The plugin gatsby-remark-source-name helped me https://www.gatsbyjs.org/packages/gatsby-remark-source-name/

It adds the name of the source so you can query it in Graphql

@erezrokah erezrokah added type: feature code contributing to the implementation of a feature and/or user facing functionality area: extensions/widgets labels May 7, 2020
@abdullahe
Copy link

Sorry for the late reply, hidden fields are meant to be used on folder collections when creating new items: https://www.netlifycms.org/docs/widgets/hidden/#hidden since they have a pre-defined uneditable value.

Hi. Is there a workaround for this? Or an alternative solution to save "invisible" data?

@erezrokah
Copy link
Contributor

Is there a workaround for this? Or an alternative solution to save "invisible" data?

You could use the preSave event to add any data you'd like:
https://www.netlifycms.org/docs/beta-features/#registering-to-cms-events

@abdullahe
Copy link

Thanks @erezrokah. This method is a bit beyond my capabilities for now. :) I added a select widget and a minor inconvenience to the user.

@lilpolymath
Copy link
Contributor

@erezrokah would it be possible to set multiple preSave events?

@erezrokah
Copy link
Contributor

@WhiteAbeLincoln
Copy link

It would be nice to have a widget that didn't display but could save a default value, regardless of whether it was in a folder or file collection, or a field under some other object widget. For my use case, I need to discriminate between different object widgets at run-time, so I'm adding a hidden "kind" field to the widget fields - but this doesn't work if I use these widgets in a file collection.

@alexis-regnaud
Copy link

alexis-regnaud commented May 2, 2021

What was the solution for that one ? I have the same problem on my side, the Collections works well, but I get a templateKey : null for my Files.

In that exemple : https://github.com/robertcoopercode/gatsby-netlify-cms/blob/master/static/admin/config.yml
They use it, but seems doesn't work at all on my side :/

@credli
Copy link

credli commented Oct 9, 2021

Perhaps a "value" widget that embeds a given value but renders as read-only on the admin interface? Kind of makes more sense to me than a hidden widget with a "default" value.

- { name: templateKey, value: "blogPost", widget: value }

@erezrokah
Copy link
Contributor

I think it makes sense to support the hidden widget (as is) for file collections.
At the moment we don't even render hidden widgets:https://github.com/netlify/netlify-cms/blob/81ce05f3fb43594036d4753f8414e6cb51340376/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControlPane.js#L163

and default values are added during entries creation:
https://github.com/netlify/netlify-cms/blob/81ce05f3fb43594036d4753f8414e6cb51340376/packages/netlify-cms-core/src/actions/entries.ts#L797

If someone is up to extend the existing code to support this, the above links should be a good place to start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: extensions/widgets pinned type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

No branches or pull requests

10 participants