I’m trying to figure out what would be the best way to write something like this on a post:
[Click here to save your spot](https://mysite.com/$CURRENT_USERNAME)
Where $CURRENT_USERNAME
would turn into a different value depending on which user was logged on.
I think I can get the current username using the plugin api inside a theme component, but I’m not sure about the best way to actually insert the link.
I guess one option would be to write a plugin that adds a new bbcode command, like discourse-details or discourse-spoiler-alert . Something like this:
[dynamic-url description="Click here to save your spot" pattern="https://mysite.com/$CURRENT_USERNAME"][/dynamic-url]
Or even more generally:
[dynamic-tag tagName="iframe" src="https://mysite.com/$CURRENT_USERNAME"][/dynamic-tag]
But I’m wondering if there is a simpler alternative.
eviltrout
(Robin Ward)
June 21, 2021, 12:58pm
2
Have you looked at the placeholder theme component?
It’s a less complicated version of what you are suggesting. Otherwise you are going to need to tap into our markdown engine to handle the replacements, but also make sure the engine has access to the information you need to replace on the client and server side. That part is tricky.
2 Likes
An alternative is also to write a theme component (less heavy than a plugin) and use wrap:
I added this feature a while back and realised I didn’t post about it. You can now use a special syntax in markdown to have it cooked and usable in theme components without having to write a plugin.
// wrapped in div.d-wrap
[wrap=baz foo=bar]Content[/wrap]
// wrapped in div.d-wrap
[wrap=baz foo=bar]
Content
[/wrap]
// wrapped in div.d-wrap
[wrap=baz foo=bar]
[/wrap]
// this one will be rendered as a span.d-wrap instead of a div.d-wrap
a [wrap=baz]Content[/wrap] b
The name of the component w…
2 Likes