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

tp.frontmatter does not respect "quotation marks" --> " #1282

Closed
mariusgerome opened this issue Dec 31, 2023 · 9 comments
Closed

tp.frontmatter does not respect "quotation marks" --> " #1282

mariusgerome opened this issue Dec 31, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@mariusgerome
Copy link

Describe the bug
I build a template that should update my old metadata for a file.

Example:
I have a file with the property tag -> category-example: "[[link]]"
the quotation marks don't get recognized with the <% tp.frontmatter["category-example"] %> command

Expected behavior
category-example: "[[link]]"
but what I get instead is: category-example: [[link]]

@mariusgerome mariusgerome added the bug Something isn't working label Dec 31, 2023
@Zachatoo
Copy link
Collaborator

You can wrap it in quotes like this as a workaround.

"<% tp.frontmatter["category-example"] %>"

@mariusgerome
Copy link
Author

You're right,
but then "list-properties" would turn into something like this:
category-example: "[[link 1]], [[link 2]], [[link 3]]"

instead of:

category-example:
- "[[link 1]]"
- "[[link 2]]"
- "[[link 3]]"

:/ :D
– M

@Zachatoo
Copy link
Collaborator

Zachatoo commented Jan 2, 2024

You're right! For list properties, you can do this to wrap each entry in quotes.

<% tp.frontmatter["category-example"].map(prop => `"${prop}"`) %>

@mariusgerome
Copy link
Author

Hey Zachatoo,

output: category-example: "item 1","item 2","item 3"
… which is "invalid frontmatter". As long as it's only one item; it works. Like: category-example: "item 1"
But with multiple items in a row like that, it's invalid.

Do you have a similar epic-code hack, that puts all of those list-values in quotation marks AND puts them on a new line?

from:

category-example: 
  - item 1
  - item 2
  - item 3
  - item 4

to:

well… the exact same thing…

… but written with a tp.frontmatter extraction template.

BTW are you a dev of the templater plugin, or just a hyper active github user?
– M

@Zachatoo
Copy link
Collaborator

Zachatoo commented Jan 4, 2024

But with multiple items in a row like that, it's invalid.

Right, needs to be wrapped in [] to be valid

[<% tp.frontmatter["category-example"].map(prop => `"${prop}"`) %>]

Do you have a similar epic-code hack, that puts all of those list-values in quotation marks AND puts them on a new line?

Could do something like this

<% tp.frontmatter["category-example"].map(prop => `\n  - "${prop}"`) %>

@Zachatoo
Copy link
Collaborator

Zachatoo commented Jan 4, 2024

I'm the current maintainer of Templater, so yes I add features and fix bugs as I have time

@mariusgerome
Copy link
Author

mariusgerome commented Jan 4, 2024

Could do something like this

<% tp.frontmatter["category-example"].map(prop => `\n  - "${prop}"`) %>

This seems to work, I got a correct output one time (only leaving , at the end of one line, but thats fine.
But I cant replicate this, something is broken with my obsidian I think. I get this Template parsing error, aborting aaaallll the time. So weird that I cant run the same exact thing twice without having to restarting obsidian :D … anyway, thats on me.

Thank you Zachatoo!
Maybe this finds a way into the docs, and as an extension to the current tp.frontmatter list.

@Zachatoo
Copy link
Collaborator

Zachatoo commented Jan 4, 2024

something is broken with my obsidian I think. I get this Template parsing error, aborting aaaallll the time.

May be a user script, though we can continue that conversation over here

#1285 (reply in thread)

Maybe this finds a way into the docs, and as an extension to the current tp.frontmatter list.

Good idea, I'll add a few more examples

Zachatoo added a commit that referenced this issue Jan 6, 2024
@Zachatoo
Copy link
Collaborator

Zachatoo commented Jan 6, 2024

Added an example to the docs, now doesn't have the , anymore

<% tp.frontmatter.categories.map(prop => `  - "${prop}"`).join("\n") %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants