Feature idea: Parameterized macros (or, "smart replacements")

Is there a way to make site- (or category-?) wide “macros” which would accept parameters?

For example, links to Fedora’s Matrix chat rooms are in the form https://matrix.to/#/#social:fedoraproject.org. I’d like people to be able to write something like {chat:social}, and have that appear as a link with the “social” parameter inserted in the proper place.

Crucially, if the macro is ever updated, all of the instances across the site should likewise follow. (Although it’s acceptable if that’s “eventually” rather than instant, as I don’t imagine wanting to use this for something that would change frequently.)

I know there’s the “watched words” feature, but I don’t see any way to do this kind of parameterized replacement.


This is doable as a small theme-component that hooks into the decoratedCooked method as documented at Developer’s guide to Discourse Themes


Not with parameters, but, try

Admin → Customize → Watched Words → Replace

The thing I’d really like to avoid is to have to pre-define all of the possible options — like, if someone makes a new chat room for home-automation, I don’t want someone to have to manually add it… I’d just like {chat:home-automation} to generate [Fedora Chat: #home-automation](https://matrix.to/#/#home-automtaion:fedoraproject.org).

Generally the way that’s handled is through oneboxing, e.g. paste the URL on a line by itself:


Understandably that’s kind of an annoying complex URL to paste though.

Yeah. And, it’s actually even worse because the URL that actually should be used is https://matrix.to/#/#home-automation:fedoraproject.org?web-instance[element.io]=chat.fedoraproject.org, which Matrix does not currently conveniently provide anywhere.

Plus, I’d like to be able to change it if, for example, the domain name changes, or their wacky parameters change, without going back and updating all of the links.

1 Like