## YAML
🔹 *parent* [[⧋ Programming|Programming]]
▫️ *related* [[Obsidian|Obsidian]], [[⏶ Espanso|Espanso]], [[⏶ Templater|Templater]]
### Code Snippets
#### Simple Matching
```yaml
matches:
- trigger: ":espanso"
replace: "Hi there!"
```
#### Trigging the Date object
Date follows the
```yaml
matches:
# Dates
- trigger: ":date"
replace: "{{mydate}}"
vars:
- name: mydate
type: date
params:
format: "%m-%d-%Y-%a"
```
#### Trigger Shell commands
Use cmd parameter
```yaml
matches:
# Shell commands
- trigger: ":shell"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: "echo Hello from your shell"
```
#### YAML front matter
Usually just use templates but this also works
```yaml
# Yaml front matter
# NOTE - Date for mydate is in ISO format - it needs to stay that way
- trigger: ":yaml"
replace: |
---
title:
id: {{zetid}}
aliases: [{{zetid}}]
tags: [ ]
date: {{mydate}}
---
vars:
- name: mydate
type: date
params:
format: "%Y-%m-%d"
- name: zetid
type: date
params:
format: "%Y%m%d%H%M%S"
```
#### Multi-line Format
```yaml
matches:
- trigger: ":yaml"
replace: |
---
title:
id: {{zetid}}
aliases: [{{zetid}}]
tags: [ ]
date: {{mydate}}
---
vars:
- name: mydate
type: date
params:
format: "%Y-%m-%d"
- name: zetid
type: date
params:
format: "%Y%m%d%H%M%S"
```
#### Anki
```yaml
- trigger: ":anki"
replace: |
START
Obsidian-basic
Back:
END
- trigger: ":deck"
replace: |
TARGET DECK
Topic::Sub-topic
```
#### References
```yaml
# Creates sup number - search with [[^]] and give unique number
- trigger: ":sup"
replace: |
<sup>[[Note-Title#^TopicNameYear|1]]</sup> - `[[^]] local` `[[^^]] global`
# Using 1-TopicNameYear makes sense because it tells you the order and makes it easier to determine exact info
- trigger: ":ref"
replace: |
"Quote from Text" [Lastname, Firstname (year). *Name of book, journal, article*](URL)^1-TopicNameYear
```
#### Misc
```yaml
# Local replacement
- trigger: ":loc"
replace: "http://localhost:8082"
# clone, may want to change
- trigger: ":clone"
replace: "npm run clone -- dcw/dcw-"
# Kase
- trigger: ":kase"
replace: "Käse"
# Shrug
- trigger: ":shrug"
replace: "¯\\_(ツ)_/¯"
# Markdown Link
- trigger: ":link"
replace: "[link name](http://)"
# Media query
- trigger: ":media"
replace: "@media screen and (min-width: @desktop-small-min) {"
# Apple symbol
- trigger: ":apple"
replace: "⌘"
```
### YAML Front Matter in Obsidian
>[!warning] Warning
> Outdated information
Some thoughts on why my current template may not be the best.
- I'm considering implementing a system like [[@ Bryan Jenks]] uses in which he only uses tags for prioritization and uses links to tag things.
- I also think that my current YAML doesn't make great sense considering adding anything to related/references essentially breaks the YAML, which has lead me to not using them. I think it would be much more effective to keep them out of the YAML and add them instead to the bottom of my notes.
- The way I'm using tags in this YAML front matter is actually creating tons of unnecessary tags that I can't really imagine how I would use it.
- It seems aliases will work correctly if I continue to use them how I am - the title is what appears in the graph view, but a search for one of my alternate aliases shows that original title - exactly what I want.
So I think I need to first create a priority system for tags - get some ideas from Bryan's videos. But then implement something more like this:
```yaml
---
title:
id: 20210227205146
aliases: [20210227205146]
tags: [📁]
date: 02-27-2021
---
```
Note - the date format needs to be in correct ISO format, so it needs to stay like that. But alternatively, I created a espanso template template for ```:longdate```
My [[⚑ Types of Notes|zettlekasten types]] all are formatted now to have this tempalte in the YAML:
```yaml
---
title: {{title}}
id: {{YYYYMMDDHHmmss}}
aliases: [{{YYYYMMDDHHmmss}}]
tags: [ ]
date: {{date:YYYY-MM-DD}}
---
```
This may lead me to the conclusion that the "Create New zettlekasten note" may be unnecessary, since it would require additional formatting rather than just creating a new note and adding a template. However, the nice thing is that it puts in the right place, and right now the only major thing I need to change is the title, so maybe I'll keep it this way.
### Aliases
alias is really alternate names you want to refer that not as - you can give multiple names with something easier to remember. Could be used for alternate spellings of something, same thing with different name, acronyms, etc. See below.
Bryan Jenks mentioned that tags can have spaces if they're in quotes, but I couldn't get this working - might need a setting changed.
I used the date object so that it always generates a date in my format.
related I can use to relate other notes.
references can be used to add book references, links to videos, etc.
```yaml
---
title: [the full title of a note about animals]
aliases: [animals]
tags:
- "cats and dogs"
- birds
date: 01-31-2021-Sun
related:
references:
---
```
`{title} {date_created}` or `{first_h1} | {date_created}`
[[YAML Template and Notes|cats]]
YAML front matter allow you to add metadata that is only visible in edit mode but not in preview mode.
There's also now a collapse display for metadata so that it can be automatically hidden in preview as well.
aliases can be listed in arrays
[Zettelkasten, ADHD, Index]
Once set, if I open double brackets, I will have alias options for each of the words defined.
Aliases allow you to select the link of your file and allow it to be inserted already with a specific preview text, so that a link doesn't need to be manually defined:
```yaml
[[name of note|alias]]
```
special characters need to be wrapped in quotes:
```yaml
[Zettelkasten, "cats & dogs", Index]
```
Aliases can also be defined as a sub-list:
```yaml
aliases:
- Zettlekasten
- ADHD
- Index
```
Indentation matters!
listing tags in the Yaml front matter also allows you to add spacing to tags and it will pick this up correctly in the tag panel:
```yaml
tags: [productivity, hello world, cats & dogs]
```
Use cases
- text case: economics Us Economics ^71e2e4
- acronyms: GTD vs Getting things done
- alternative/language spellings: Odin vs odinn, Educacion vs Educacion, USA o United States of America / United States / U.S.A. / US / U.S
- Multi-lingual: Recipes vs Recetas
- Convenience for filenames: Could alias include forbidden symbols?
- Not including the ZK prefix - just have the alias display the text
- abbreviations synonyms/homonyms, etc: Drug names.
- Benadryl,
- diphenhydramine,
- Unisom,
- Sominex,
- 2-(diphenylmethoxy)-N,
- N-dimethylethanamine -all the same drug,
- Vitamin B1 and Thiamine are the same thing
- short/convenient references: [[prefrontal cortex|dorsolateral prefrontal cortex]],
- plurals
- pseudonyms
### Other Obsidian Uses
- cssclass
- Create a different theme for specific notes - Used in [[Top Priorities]]
- links, related, references - None of these yet work in Obsidian so I've removed them from my templates
- `related` for notes that are not directly placeable inline but related to the note
- `reference`
- for reference to the parent literature note, or just parent note
- also citing book you got an idea from
- `links` - could use, but he argues that it's redundant as links are inline in your text. I have it on a lot of my pages just because I think it could be useful or quick-linking later, in addition to inline.
https://publish.obsidian.md/bryan-jenks/INDEX
## References
[YAML reference](https://ymlthis.r-lib.org/reference/yml_reference.html)^1-YAMLReference
[YAML format](https://symfony.com/doc/current/components/yaml/yaml_format.html)^2-YAMLFormat
[Format date in Shell](https://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/)^3-DateFormatShell
[ISO 8601 Format](https://www.iso.org/iso-8601-date-and-time-format.html)^4-ISOFormat
[Bryan Jenks Video on YAML](https://www.youtube.com/watch?v=rAoFGGMG-0g)^5-BryanJenksYAML