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

New Syntax: No nesting possible? (Trying to emulate old {{tp_title_picture}}) #97

Closed
Moonbase59 opened this issue Apr 11, 2021 · 2 comments
Closed
Assignees
Labels

Comments

@Moonbase59
Copy link

@Moonbase59 Moonbase59 commented Apr 11, 2021

See also https://forum.obsidian.md/t/templater-plugin-new-syntax-emulate-tp-title-picture/16324.

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?

I think this question is of general interest, because the new syntax allows for easy use of parameters, which in turn might come from other Templater variables or functions.

In general, the new syntax took away a little (memorized) ease-of-use, but I like the new more structured approach in spite of making the learning curve steeper. It will allow for much more template functionality.

@SilentVoid13
Copy link
Owner

@SilentVoid13 SilentVoid13 commented Apr 11, 2021

Hey @Moonbase59, you can nest variables and functions if you want.
Because you already declared a command using <% and %>, you don't have to re-declare it.
The correct syntax for what you'd like to do is:

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

Tell me if this works for you.

@Moonbase59
Copy link
Author

@Moonbase59 Moonbase59 commented Apr 11, 2021

Works just great, thanks for the fast answer and great explanation!

@Moonbase59 Moonbase59 closed this Apr 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants