obsidianmd / obsidian-clipper

Highlight and capture the web in your favorite browser. The official Web Clipper extension for Obsidian.
https://obsidian.md/clipper
MIT License
1k stars 45 forks source link

Conditions in templates #170

Open ilyachch opened 4 hours ago

ilyachch commented 4 hours ago

I think, it would be great to have an option to use conditions in templates.

I think it's syntax should be like:

{%if <condition1>%}
...block to include if <condition1> is true
{%elif <condition2>%}
...block to include if <condition2> is true
{%else%}
...block to include if <condition1> and <condition2> both are false
{%endif%}

also it should support inversion:

{%if !<condition1>%}
...block to include if <condition1> is false
{%endif%}

For example, a common template could be like this:

# {{title}}

{%if highlights%}

{{highlights|template:"${text}"|callout:("INFO", "Important", true)}}

{%endif%}

{{content}}

## Links

- [{{title}}]({{url}})

Currently if there are no highlights, there will be empty callout.

But with conditions, callout will be only if there is any highlight

Also it can work with selectors:

{%if selector:.some_block%}
...show some things if .some_block element presents on the page
{%endif%}
kepano commented 3 hours ago

See roadmap