Originally posted by bwklein June 13, 2022
I would like to show only the fields that are required based on some boolean or choice field selections.
For example, I have a 'Heading' partial that can either have text based title or a logo based heading.
I would like to allow the editor to choose if they want a text or logo based heading with a boolean choice like "Logo Heading?"
If true, then I would like to show them a Logo choice field and a string field for 'Classes' that they can pass in to style the logo. Essentially showing them a Field Group for the 'Logo' settings.
If false, then I would like to show the fieldgroup for the "Text" heading data.
### Discussed in https://github.com/estruyf/vscode-front-matter/discussions/357
<div type='discussions-op-text'>
<sup>Originally posted by **bwklein** June 13, 2022</sup>
I would like to show only the fields that are required based on some boolean or choice field selections.
For example, I have a 'Heading' partial that can either have text based title or a logo based heading.
I would like to allow the editor to choose if they want a text or logo based heading with a boolean choice like "Logo Heading?"
If `true`, then I would like to show them a Logo choice field and a string field for 'Classes' that they can pass in to style the logo. Essentially showing them a Field Group for the 'Logo' settings.
If `false`, then I would like to show the fieldgroup for the "Text" heading data.</div>
## Solution
```json
{
"title": "Logo Heading",
"name": "logoHeading",
"type": "string",
"when": {
"property": "heading",
"operator": "eq",
"value": true
}
}
```
<!-- github-sync-id:1273125397 -->
Love this idea. Another use case for conditional metadata is when it applies only to section pages (for example, _index.md files for a hugo site).
Love this idea. Another use case for conditional metadata is when it applies only to section pages (for example, `_index.md` files for a hugo site).
<!-- github-comment-id:1236021850 -->
@estruyf I finally got some time to dig in today, looking to make the section-only metadata (in my case, controlling whether a section is collapsed or flattened in site navigation) conditional. I'm not savvy enough with the code base yet to follow things around properly, but I can intuitively see how this implementation works conditionally on other metadata fields - is there a way to reference the file name in this implementation?
I'm looking to make something like this work:
Example JSON Definition
{"name":"default","$schema":"https://beta.frontmatter.codes/config/taxonomy.contenttypes.schema.json","pageBundle":false,"fields":[{"title":"Platen","type":"fields","name":"Platen","fields":[{"title":"Menu options","name":"Menu","type":"fields","fields":[{"title":"Flatten section in site menu","name":"FlattenSection","type":"boolean","when":{"fieldRef":"file.baseName","operator":"eq","value":"_index.md"}},{"title":"Collapse section in site menu","name":"CollapseSection","type":"boolean","when":{"fieldRef":"file.baseName","operator":"eq","value":"_index.md"}},{"title":"Hide from site menu","description":"Applicable to any page.","name":"Hide","type":"boolean"}]}]}]}
Where the Platen.Menu.Hide setting is available for any page but Platen.Menu.FlattenSection and Platen.Menu.CollapseSection are only visible/usable for section pages, which always have a file name of _index.md.
@estruyf I finally got some time to dig in today, looking to make the section-only metadata (in my case, controlling whether a section is collapsed or flattened in site navigation) conditional. I'm not savvy enough with the code base yet to follow things around properly, but I can intuitively see how this implementation works conditionally on other metadata fields - is there a way to reference the _file name_ in this implementation?
I'm looking to make something _like_ this work:
<details>
<summary>Example JSON Definition</summary>
```json
{
"name": "default",
"$schema": "https://beta.frontmatter.codes/config/taxonomy.contenttypes.schema.json",
"pageBundle": false,
"fields": [
{
"title": "Platen",
"type": "fields",
"name": "Platen",
"fields": [
{
"title": "Menu options",
"name": "Menu",
"type": "fields",
"fields": [
{
"title": "Flatten section in site menu",
"name": "FlattenSection",
"type": "boolean",
"when": {
"fieldRef": "file.baseName",
"operator": "eq",
"value": "_index.md"
}
},
{
"title": "Collapse section in site menu",
"name": "CollapseSection",
"type": "boolean",
"when": {
"fieldRef": "file.baseName",
"operator": "eq",
"value": "_index.md"
}
},
{
"title": "Hide from site menu",
"description": "Applicable to any page.",
"name": "Hide",
"type": "boolean"
}
]
}
]
}
]
}
```
</details>
Where the `Platen.Menu.Hide` setting is available for any page but `Platen.Menu.FlattenSection` and `Platen.Menu.CollapseSection` are only visible/usable for section pages, which always have a file name of `_index.md`.
<!-- github-comment-id:1323773350 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Discussed in https://github.com/estruyf/vscode-front-matter/discussions/357
Originally posted by bwklein June 13, 2022
I would like to show only the fields that are required based on some boolean or choice field selections.
For example, I have a 'Heading' partial that can either have text based title or a logo based heading.
I would like to allow the editor to choose if they want a text or logo based heading with a boolean choice like "Logo Heading?"
If
true, then I would like to show them a Logo choice field and a string field for 'Classes' that they can pass in to style the logo. Essentially showing them a Field Group for the 'Logo' settings.If
false, then I would like to show the fieldgroup for the "Text" heading data.Solution
Love this idea. Another use case for conditional metadata is when it applies only to section pages (for example,
_index.mdfiles for a hugo site).Good news @michaeltlombardi and @bwklein, this is now supported in the latest beta version.
Sample
Operator
The following operators are supported:
eqneqcontainsnotContainsstartsWithendsWithgtgteltlte@estruyf I finally got some time to dig in today, looking to make the section-only metadata (in my case, controlling whether a section is collapsed or flattened in site navigation) conditional. I'm not savvy enough with the code base yet to follow things around properly, but I can intuitively see how this implementation works conditionally on other metadata fields - is there a way to reference the file name in this implementation?
I'm looking to make something like this work:
Example JSON Definition
Where the
Platen.Menu.Hidesetting is available for any page butPlaten.Menu.FlattenSectionandPlaten.Menu.CollapseSectionare only visible/usable for section pages, which always have a file name of_index.md.