Can I automatically create an alias with a specific ("@") prefix?

I like the idea of having an alias for my contact notes with a prefix of @ for future linking (e.g. “@Jane Doe”). However when I have tried adding
"aliases: - <% “@”+tp.file.title %> "
to the frontmatter, Obsidian doesn’t like it and the front matter appears in red. Any ideas of how I could do this or alternatives?

The frontmatter being flagged as invalid in the template doesn’t matter — once you trigger the template in a note and its syntax is replaced with other text there, the results will probably be valid (try it and see).

It isn’t the template that is a problem, as you say when the template is triggered and the syntax is replaced Obsidian highlights the @ symbol and shows the front matter as YAML all in red. When I delete the @ the front matter immediately reverts to the property view

I see. I don’t remember that symbol being part of YAML syntax but it may be. If so, wrapping the property value in quote marks should fix it.

I have used <% “@”+tp.file.title.append %> with Templater. This becomes “@undefined” with the @ highlighted

Are the quote marks straight ("") or fancy (“”)? They need to be straight. I assume that’s what you have in your file and they were just auto-converted by the forum, but I have to ask. When you post code in the forum, marking it as code like you would in Obsidian makes it clearer.

1 Like

<% await "@"+tp.file.title.append %> there we go - thanks

Did this work and produce a valid alias for you? In order for an alias to have an @ I had to surround the entire alias in quotes, and that means to do something like the following within Templater:

<% '"@' + tp.file.title +'"' %>

I’m using single straight quotes to surround the double straight quotes, so that I don’t have to escape it. And I add those double straight quotes on either end, so that the resulting alias becomes: "@Jane Doe".

The full example would then become:

aliases:
- <% '"@' + tp.file.title + '"' %>

Or maybe simpler:

aliases:
- "@<% tp.file.title %>"

Either version produces fully compliant aliases.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.