Templater
Templater copied to clipboard
Create working "live" (image) links using Templater and YAML frontmatter
Is your feature request related to a problem? Please describe. I’m desperately trying to construct working "live" links using Templater (somehow like Dataview’s "elinks"). This seems currently impossible because apparently Obsidian’s Markdown renderer hits in before Templater gets a chance.
In an ideal world, all things Templater should be finished before it gets rendered by Obsidian (maybe using a MarkdownRenderChild
?). Maybe this is not possible, because Templater stuff isn’t in a code block, I don’t know.
If it’s not easily possible using what we have, maybe Templater functions to create
- internal (wikilink) links,
- external links,
- image links, and
- embed links
could be added?
Related: #242
Describe the solution you'd like
Ability to create "live" constructed links using Templater and YAML frontmatter, in both <%+
and—more important—<%+*
(Javascript) modes. External, internal (wikilinks), and—for my use case—embed and/or image links would be great.
Describe alternatives you've considered
Here are some of my desperate attempts:
---
location: [51.133333,10.416667]
---
# Test Weather
**Here is the link, hardcoded:**
![Wetter](https://wttr.in/51.133333,10.416667_0tqp_lang=en.png)
_This works but is not dynamic._
**Here I try to use Templater instead:**
![Wetter](https://wttr.in/<%+ tp.frontmatter.location[0] %>,<%+ tp.frontmatter.location[1] %>_0tqp_lang=en.png)
_This just creates some text but not an image._
**Here I try `<img>`:**
<img alt="Wetter" src="https://wttr.in/<%+ tp.frontmatter.location[0] %>,<%+ tp.frontmatter.location[1] %>_0tqp_lang=en.png" referrerpolicy="no-referrer">
_This results in a broken image._
**Here I try to construct the whole `<img>` link _within_ Templater:**
<%+* tR+="<img alt='Wetter' src='https://wttr.in/" + tp.frontmatter.location[0] + "," + tp.frontmatter.location[1] + "_0tqp_lang=en.png' referrerpolicy='no-referrer'>" %>
_This doesn’t work because apparently Obsidian hits in and interprets the `<img …` **before** Templater gets its chance._
**Here I try to construct the whole `<img>` within Templater again, using a trick so Obsidian doesn’t see the `<img …`:**
<%+* tR += '<' + 'img src="https://wttr.in/{0},{1}_0tqp_lang=en.png"'.format(tp.frontmatter.location[0], tp.frontmatter.location[1]) + '>' %>
_This again only returns text._
Additional context
Screenshot of above attempts:
Similar to #192