Logseq-style "macros" in Obsidian?

I’m exploring the idea of transitioning from Logseq to Obsidian, but I’m stuck on what I could replace Logseq’s macros with.


Macros in Logseq are code snippets that can take multiple variables and display text and code with it. So, say, if I define
"genwiki" "[$1](https://genshin-impact.fandom.com/wiki/$1)"
in the config file, then I can write
{{genwiki Rural Concealment}}
on a page, and it automatically displays it as a properly formatted link in live preview mode, while retaining the macro format in the code for easy editing.

It can also do HTML, like if I define
"progress" "<span class=\"progress-bar\"><progress value=\"$1\" max=\"$2\">$1/$2</progress><span>$1/$2</span></span>"
then I can insert
{{progress 27,50}}
in a page, and it will output a progress bar that I can further style in CSS, and easily update the values later.

Is there any way I could do something similar in Obsidian either natively or with a plugin? (I only know HTML and CSS, not any programming languages, so this simple macro language worked great for me.)


Can’t seem to edit the original message; just wanted to add that this idea seems similar to what I’d like to be able to do:

Currently the plugins Templater (can do Js scripts) and DataView (can do Js) are the closest that can be used to get anything like what you need.
But there’s some getting used to.
Good thing about Obsidian is that the customization is not limited or you can use another plugin’s API. Plugins like QuickAdd, Modal Forms, Meta Bind, MetaData Menu etc. have potential for various use cases.

So one needs to learn the Obsidian trade a bit. Get some skills and can be really productive.

Thanks for the tips - I checked those plugins out, but they seem too advanced for my non-programmer brain. I tried learning Javascript a few times in the past, but my mind just doesn’t take it in.

For now I found a jank-ass solution of just using Excel as a templater with CONCAT formulas outputting HTML code with variables that I can copy-paste into Obsidian, but this method will probably provide enough friction that I’ll minimise how much I’m using these “macros” and just stick to plain markdown, HTML and emojis (for icons) where I can.

But I hope someone will make a plugin someday that would help non-programmers access these Logseq-style macros in Obsidian too :pensive:

I’ve got a question related to the usage of your “macros”, and that is when you use a macro in some note will the entire text be replaced with the expanded value, or can you later on change it and all insertions of the macro will be updated?

An example

  • version 1 of the greet macro: hello $1
  • if you now insert {{greet world}} in a note that would be changed to “hello world” (or will it be va textual replacement to “hello world”?)
  • if you now make version 2 of greet to become hi $1, will the previously insertion stay at “hello world”, or will it become “hi world”? Or is it just a new insertion, i.e. {{greet again}}, that will use the updated version and produce “hi again”?

If it’s a one time expansion you can use various plugins like Templater and possibly Text snippet/expander. If it’s a dynamic expansion you’ll need to use other tools like Dataview or similar.

1 Like

They are changeable and the output is updated accordingly. I’ve looked up Dataview, but can’t find a resource on how I would create something like my examples in the original post. Its main use seems to be for collating lists of pages that fit certain criteria, but I use Logseq’s macros as sort-of placeholders (with variables) to avoid having to type out longer pieces of inline HTML code.

But thank you, that Text Snippet plugin does work for my use case, as I rarely change these macros after creation (and if I needed to change them, I could probably just do a mass search and replace in VSCode).

Latex Suite is designed for math replacements, but it’s very flexible and can do any text replacement really.

1 Like

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