First at all, a really nice project. I appreciate using this extension.
For now i don´t have understand how to use variables in the frontmatter conent-type definition.
When creating a new content the title: and slug: are filled with the name of the filename.
The article.md template file has two variable definitions.
Example:
title: "{{name}}"
slug: "/{{kebabCase name}}/"
Is it somehow possible to define this variable for other taxonomy content types.
For now only the title: and slug: has the filename filled out.
title: created filename
slug: created-filename
permalink: '{{name}}'
How can i resolve this?
First at all, a really nice project. I appreciate using this extension.
For now i don´t have understand how to use variables in the frontmatter conent-type definition.
When creating a new content the title: and slug: are filled with the name of the filename.
The **article.md** template file has two variable definitions.
Example:
```
title: "{{name}}"
slug: "/{{kebabCase name}}/"
```
Is it somehow possible to define this variable for other taxonomy content types.
Example:
```
title: "{{name}}"
slug: "/{{kebabCase name}}/"
permalink: "{{name}}"
```
For now only the title: and slug: has the filename filled out.
```
title: created filename
slug: created-filename
permalink: '{{name}}'
```
How can i resolve this?
<!-- github-sync-id:1103046803 -->
@wemasoe thanks for opening this issue. These placeholders are a leftover from when the extension didn't support content types.
At the moment only the title and slug are automatically propagated on the creation. In the upcoming version, you can also define default values for your content type fields.
Placeholder support is indeed a good one to get added as well.
@wemasoe thanks for opening this issue. These placeholders are a leftover from when the extension didn't support content types.
At the moment only the `title` and `slug` are automatically propagated on the creation. In the upcoming version, you can also define `default` values for your content type fields.
Placeholder support is indeed a good one to get added as well.
<!-- github-comment-id:1012986784 -->
Placeholder support is indeed a good one to get added as well.
this would be very nice 👍
@estruyf thx for the reply.
> Placeholder support is indeed a good one to get added as well.
this would be very nice 👍
<!-- github-comment-id:1013052662 -->
well, i am just diving a little into the code.
i thnk it would be nice when generating the template to reference to a helper variable?
Maybe there are other methods solving this?
in this particular need i would like to use a permalink: like "filename.html"
There are already constants like in ArticleHelper.ts:
prefix could be null.
suffix could also be null (".html", ".json", ".js")
i am not sure what would be most effective.
> placeholders you'd like to use.
well, i am just diving a little into the code.
i thnk it would be nice when generating the template to reference to a helper variable?
Maybe there are other methods solving this?
in this particular need i would like to use a permalink: like "filename.html"
There are already constants like in `ArticleHelper.ts`:
`export const SETTING_TAXONOMY_CONTENT_TYPES = "taxonomy.contentTypes";`
```
export interface Field {
title?: string;
name: string;
type: "string" | "number" | "datetime" | "boolean" | "image" | "choice" | "tags" | "categories" | "draft" | "taxonomy";
choices?: string[] | Choice[];
single?: boolean;
multiple?: boolean;
isPreviewImage?: boolean;
hidden?: boolean;
taxonomyId?: string;
}
```
there is also already a taxonomy type
```
TaxonomyType.ts
export enum TaxonomyType {
Tag = 1,
Category
}
```
suggestion1:
```
taxonomy_helper_varname1: $var_prefix
taxonomy_helper_varname2: "{{title}}" (or anything else defined in template fields: "slug", "title", "date", "or taxonomy" ,"fieldname")
taxonomy_helper_varname3: $var_suffix
taxonomy_helper_varname_concatenate: taxonomy_helper_varname[0-2]
title: created filename
slug: created-filename
permalink: '{{taxonomy_helper_varname_concatenate}}'
type: documentation
```
or maybe like this?
suggestion2:
```
taxonomy_helper_varname: "{{title}}" (or anything else defined in template fields: "slug", "title", "date", "or taxonomy" ,"fieldname")
title: created filename
slug: created-filename
permalink: '{{taxonomy_helper_varname}}'
type: documentation
```
> https://frontmatter.codes/docs/content-types#define-your-own-type
```
"frontMatter.taxonomy.contentTypes": [
{
"name": "default",
"fields": [
...
]
},
{
"name": "documentation",
"fields": [
...
]
}
]
```
ContentType is defined as follow in the documentation section fields:
`frontmatter.json`
```
{
"title": "Permalink",
"name": "permalink",
"type": "string"
},
```
well now i am on my limit :-)
```
"frontMatter.taxonomy.customTaxonomy": [
{
"id": "permalink",
"options": [
"prefix",
"taxonomy_helper_varname(read from template definition field (taxonomy_helper_varname))",
"suffix",
]
}
]
```
or
```
{
"title": "Permalink",
"name": "permalink",
"type": "choice",
"choices": ["taxonomy_helper_varname",".html", ".json", ".js", "prefix"]
},
```
prefix could be null.
suffix could also be null (".html", ".json", ".js")
i am not sure what would be most effective.
<!-- github-comment-id:1013143249 -->
There are already constants like in ArticleHelper.ts:
These are the extension setting constants in order to understand how your environment is configured.
there is also already a taxonomy type
Taxonomy is a list of predefined data like tags/categories/custom-data to use in your front matter article content. Not really used for defining the helpers, or at least I don't see how we could use it for that.
Think I'm not really following with the logic. Just to reclarify for my mind. You want to be able to define placeholders that will be updated once contents get created. For instance, a unique ID or GUID can be one of the placeholders to include.
Others could be:
{{title}}: Returns the title of the page
{{slug}}: Returns a sanitized title of the page concatenated with -'s
{{now}}: Returns the current time string
...
Your example of supporting a permalink would require extra logic. As you want to include a prefix and suffix. I think it might complicate it a bit, as there are various ways to configure the extension.
Think a new setting like frontMatter.content.placeholders would be more appropriate, but instead of defining options/fields, what if you'd define a script that the extension executes? You get the file path, front matter data, ... All you need to do is create the value to insert into the file. A bit like we do on the custom actions/scripts - https://frontmatter.codes/docs/custom-actions
> There are already constants like in `ArticleHelper.ts:`
These are the extension setting constants in order to understand how your environment is configured.
> there is also already a taxonomy type
Taxonomy is a list of predefined data like tags/categories/custom-data to use in your front matter article content. Not really used for defining the helpers, or at least I don't see how we could use it for that.
Think I'm not really following with the logic. Just to reclarify for my mind. You want to be able to define placeholders that will be updated once contents get created. For instance, a `unique ID` or `GUID` can be one of the placeholders to include.
Others could be:
- `{{title}}`: Returns the title of the page
- `{{slug}}`: Returns a sanitized title of the page concatenated with `-`'s
- `{{now}}`: Returns the current time string
- ...
Your example of supporting a `permalink` would require extra logic. As you want to include a prefix and suffix. I think it might complicate it a bit, as there are various ways to configure the extension.
Think a new setting like `frontMatter.content.placeholders` would be more appropriate, but instead of defining options/fields, what if you'd define a script that the extension executes? You get the file path, front matter data, ... All you need to do is create the value to insert into the file. A bit like we do on the `custom actions/scripts` - https://frontmatter.codes/docs/custom-actions
<!-- github-comment-id:1013193382 -->
Or `frontMatter.content.placeholders` could be as follows:
```json
{
"frontMatter.content.placeholders": [
{
"id": "permalink",
"value": "<prefix>-{{slug}}<suffix>"
}
]
}
```
> `<prefix>` and `<suffix>` will need to be added by you. For example:
```json
{
"frontMatter.content.placeholders": [
{
"id": "permalink",
"value": "/docs/{{slug}}.html"
}
]
}
```
In your template or content type, you define the value of the field to: `{{permalink}}`.
```yaml
---
permalink: {{permalink}}
---
```
This results in a front matter data value as:
```yaml
---
permalink: /blog/placeholder-documentation.html
---
```
<!-- github-comment-id:1013200913 -->
{{title}}: Returns the title of the page
{{slug}}: Returns a sanitized title of the page concatenated with -'s
{{now}}: Returns the current time string
...
Your answer also clarified the script section you mentioned, for me.
@estruyf: thx a lot for your detailed answers
> ```json
> {
> "frontMatter.content.placeholders": [
> {
> "id": "permalink",
> "value": "<prefix>-{{slug}}<suffix>"
> }
> ]
> }
> ```
yes :-) that looks like a fine solution :-)
Like you already mentioned.
>
> Others could be:
>
> {{title}}: Returns the title of the page
> {{slug}}: Returns a sanitized title of the page concatenated with -'s
> {{now}}: Returns the current time string
> ...
Your answer also clarified the script section you mentioned, for me.
@estruyf: thx a lot for your detailed answers
<!-- github-comment-id:1013223968 -->
The first implementation of this enhancement has been added to the beta.
Currently supported placeholders are: {{title}} and {{slug}}. If you want to add custom placeholders, you can add this in your settings or frontmatter.json file as follows:
The known placeholders from Front Matter itself can also be used in the custom ones.
The first implementation of this enhancement has been added to the beta.
Currently supported placeholders are: `{{title}}` and `{{slug}}`. If you want to add custom placeholders, you can add this in your settings or `frontmatter.json` file as follows:
```json
"frontMatter.content.placeholders": [
{
"id": "permalink",
"value": "/blog/{{slug}}.html"
}
]
```
The known placeholders from Front Matter itself can also be used in the custom ones.
<!-- github-comment-id:1013742411 -->
"optimize slug" can not be selected without a slug: definition in the frontmatter of the generated file.
@estruyf thank you for the enhancement implementation. This realy helps me a lot.
When using the new frontmatter setting it works when using templates. Like the Article.md
```json
"frontMatter.content.placeholders": [
{
"id": "permalink",
"value": "/blog/{{slug}}.html"
}
]
```
How do i define it in my own contenttype settings?
With this configuration i don´t get the placeholder been rewritten.
```json
"frontMatter.taxonomy.contentTypes": [
{
"name": "default",
"fields": [
...
]
},
{
"name": "documentation",
"fields": [
...
{
"title": "Permalink",
"name": "permalink",
"type": "string"
},
...
]
}
]
```
Output:
```yaml
---
title: newfile
permalink: ''
description: ''
date: '2022-01-16T11:51:53.791Z'
preview: ''
draft: ''
tags: ''
categories: ''
weight: ''
test: ''
sidebar: ''
type: documentation
---
```
"optimize slug" can not be selected without a `slug:` definition in the frontmatter of the generated file.
<!-- github-comment-id:1013861965 -->
"optimize slug" can not be selected without a slug: definition in the frontmatter of the generated file.
This is another enhancement, it might require a content/front matter scan in order to enable/disable it.
> Content type
- in your content type, you can now use the `default` property and set it to `{{permalink}}` in your case.
```JSON
{
"title": "Permalink",
"name": "permalink",
"type": "string",
"default": "{{permalink}}"
}
```
> "optimize slug" can not be selected without a slug: definition in the frontmatter of the generated file.
- This is another enhancement, it might require a content/front matter scan in order to enable/disable it.
<!-- github-comment-id:1013925628 -->
> * enhancement, it might require a content/front matter scan in order to enable/disable it.
@estruyf yes that would be fine
the placeholder is not beeing set, when using choice.
```json
...
{
"title": "Permalink1",
"name": "permalink1",
"type": "choice",
"choices": [
"{{permalink}}",
"{{title}}"
]
},
...
"frontMatter.content.placeholders": [
{
"id": "permalink",
"value": "{{title}}.html"
}
],
...
```
<!-- github-comment-id:1015084347 -->
Choice fields and taxonomy fields cannot be used like this. They can only be used to select a predefined value.
Can you try to explain your use case or how you want to use it?
Choice fields and taxonomy fields cannot be used like this. They can only be used to select a predefined value.
Can you try to explain your use case or how you want to use it?
<!-- github-comment-id:1015258307 -->
Choice fields and taxonomy fields cannot be used like this. They can only be used to select a predefined value.
Can you try to explain your use case or how you want to use it?
i just played around and tried some things out to check how dynamic the placeholder and variables are in the dashboard.
> Choice fields and taxonomy fields cannot be used like this. They can only be used to select a predefined value.
>
> Can you try to explain your use case or how you want to use it?
i just played around and tried some things out to check how dynamic the placeholder and variables are in the dashboard.
<!-- github-comment-id:1015895337 -->
The optimize slug button, now updates all fields that had a default value set to the {{slug}} placeholder + any custom placeholders that depend on {{slug}} as well.
The `optimize slug` button, now updates all fields that had a default value set to the `{{slug}}` placeholder + any custom placeholders that depend on `{{slug}}` as well.
<!-- github-comment-id:1016438243 -->
The optimize slug button, now updates all fields that had a default value set to the {{slug}} placeholder + any custom placeholders that depend on {{slug}} as well.
that sounds good. But can you give an example?
i have tried this?
that is how i understood the feature?
> The `optimize slug` button, now updates all fields that had a default value set to the `{{slug}}` placeholder + any custom placeholders that depend on `{{slug}}` as well.
that sounds good. But can you give an example?
i have tried this?
that is how i understood the feature?
```json
{
"title": "Slugtest",
"name": "slugtest",
"type": "string",
"default": "{{slug}}"
},
```
```json
"frontMatter.content.placeholders": [
{
"id": "slug",
"value": "{{slug}}.html"
}
],
```
<!-- github-comment-id:1016839199 -->
No, it works differently. `{{slug}}` is a known placeholder from Front Matter, what you try to do is overwrite it and will not work.
What will work, is if you go back to the `permalink` approach:
```json
{
"title": "Slugtest",
"name": "slugtest",
"type": "string",
"default": "{{permalink}}"
}
```
```json
"frontMatter.content.placeholders": [
{
"id": "permalink",
"value": "{{slug}}.html"
}
],
```
<!-- github-comment-id:1017254533 -->
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.
First at all, a really nice project. I appreciate using this extension.
For now i don´t have understand how to use variables in the frontmatter conent-type definition.
When creating a new content the title: and slug: are filled with the name of the filename.
The article.md template file has two variable definitions.
Example:
Is it somehow possible to define this variable for other taxonomy content types.
Example:
For now only the title: and slug: has the filename filled out.
How can i resolve this?
@wemasoe thanks for opening this issue. These placeholders are a leftover from when the extension didn't support content types.
At the moment only the
titleandslugare automatically propagated on the creation. In the upcoming version, you can also definedefaultvalues for your content type fields.Placeholder support is indeed a good one to get added as well.
@estruyf thx for the reply.
this would be very nice 👍
Feel free to suggest some placeholders you'd like to use.
well, i am just diving a little into the code.
i thnk it would be nice when generating the template to reference to a helper variable?
Maybe there are other methods solving this?
in this particular need i would like to use a permalink: like "filename.html"
There are already constants like in
ArticleHelper.ts:export const SETTING_TAXONOMY_CONTENT_TYPES = "taxonomy.contentTypes";there is also already a taxonomy type
suggestion1:
or maybe like this?
suggestion2:
ContentType is defined as follow in the documentation section fields:
frontmatter.jsonwell now i am on my limit :-)
or
prefix could be null.
suffix could also be null (".html", ".json", ".js")
i am not sure what would be most effective.
These are the extension setting constants in order to understand how your environment is configured.
Taxonomy is a list of predefined data like tags/categories/custom-data to use in your front matter article content. Not really used for defining the helpers, or at least I don't see how we could use it for that.
Think I'm not really following with the logic. Just to reclarify for my mind. You want to be able to define placeholders that will be updated once contents get created. For instance, a
unique IDorGUIDcan be one of the placeholders to include.Others could be:
{{title}}: Returns the title of the page{{slug}}: Returns a sanitized title of the page concatenated with-'s{{now}}: Returns the current time stringYour example of supporting a
permalinkwould require extra logic. As you want to include a prefix and suffix. I think it might complicate it a bit, as there are various ways to configure the extension.Think a new setting like
frontMatter.content.placeholderswould be more appropriate, but instead of defining options/fields, what if you'd define a script that the extension executes? You get the file path, front matter data, ... All you need to do is create the value to insert into the file. A bit like we do on thecustom actions/scripts- https://frontmatter.codes/docs/custom-actionsOr
frontMatter.content.placeholderscould be as follows:In your template or content type, you define the value of the field to:
{{permalink}}.This results in a front matter data value as:
yes :-) that looks like a fine solution :-)
Like you already mentioned.
Your answer also clarified the script section you mentioned, for me.
@estruyf: thx a lot for your detailed answers
The first implementation of this enhancement has been added to the beta.
Currently supported placeholders are:
{{title}}and{{slug}}. If you want to add custom placeholders, you can add this in your settings orfrontmatter.jsonfile as follows:The known placeholders from Front Matter itself can also be used in the custom ones.
@estruyf thank you for the enhancement implementation. This realy helps me a lot.
When using the new frontmatter setting it works when using templates. Like the Article.md
How do i define it in my own contenttype settings?
With this configuration i don´t get the placeholder been rewritten.
Output:
"optimize slug" can not be selected without a
slug:definition in the frontmatter of the generated file.defaultproperty and set it to{{permalink}}in your case.@estruyf yes that would be fine
the placeholder is not beeing set, when using choice.
Choice fields and taxonomy fields cannot be used like this. They can only be used to select a predefined value.
Can you try to explain your use case or how you want to use it?
i just played around and tried some things out to check how dynamic the placeholder and variables are in the dashboard.
Ok, that makes it clear! Thanks for the feedback 🙏
The
optimize slugbutton, now updates all fields that had a default value set to the{{slug}}placeholder + any custom placeholders that depend on{{slug}}as well.that sounds good. But can you give an example?
i have tried this?
that is how i understood the feature?
No, it works differently.
{{slug}}is a known placeholder from Front Matter, what you try to do is overwrite it and will not work.What will work, is if you go back to the
permalinkapproach:it did not show any action.
Latest applied fix will resolve this issue.
@estruyf thx :-)