Templater plugin new syntax: Emulate {{tp_title_picture}}?

With the Templater plugin’s new syntax, I’m trying to emulate the old {{tp_title_picture}} behaviour (generate an unsplash.com image link based on the note’s title).

I tried both

<% tp.web.random_picture("1920x1080", "<% tp.file.title %>") %>
<% tp.web.random_picture("1920x1080", <% tp.file.title %>) %>

but it seems Templater cannot handle nested variables/functions.

Non-nested calls like

<% tp.web.random_picture("1920x1080", "Example") %>

work fine.

How would I do this? Or other “nested” Templater commands?

See also: New Syntax: No nesting possible? (Trying to emulate old {{tp_title_picture}}) · Issue #97 · SilentVoid13/Templater · GitHub


You don’t need to wrap the second call in <% %>

This should work:

<% tp.web.random_picture(“1920x1080”, tp.file.title) %>


Wow, works fine! Thanks for the fast answer.

So can I assume every tp. variable/function gets expanded within the same set of <% … %>?

Yep exactly! Once you’re in a command block you can reference any command. Or even just plain ol javascript:

<% moment().now() %> for example.

1 Like

Now this opens a whole lot of new templating possibilities—well done!

Despite having to change my old templates, and the steeper learning curve, I quite like the new more structured approach a lot. Thanks for this!

Just to make things a little more complete, here are my replacements for some often-used “old style” Templater calls:

Old style New Syntax
{{tp_title}} <% tp.file.title %>
{{tp_date}} <% tp.date.now() %>
{{tp_time}} <% tp.date.now("HH:mm") %>
{{tp_random_picture}} <% tp.web.random_picture() %>
{{tp_title_picture}} <% tp.web.random_picture("1600x900", tp.file.title) %>
{{tp_daily_quote}} <% tp.web.daily_quote() %>
{{tp_cursor}} <% tp.file.cursor() %>

This list is not complete, just the ones I used most often. Maybe it helps someone with the changeover from old to new syntax.


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