איך להשתמש במשתנים/bbcode בפוסט?

סיכום מבוסס בינה מלאכותית

The discussion revolves around dynamically inserting user-specific variables, like $CURRENT_USERNAME, into posts using BBCode. Nacho_Caballero proposes creating a custom BBCode plugin to handle dynamic URLs, such as [dynamic-url], but seeks a simpler solution. eviltrout suggests using the placeholder theme component, which is a lighter alternative for handling dynamic content. j.jaffeux recommends a theme component with wrap as another lightweight option, avoiding the complexity of a full plugin while still enabling dynamic content rendering.

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.

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.

An alternative is also to write a theme component (less heavy than a plugin) and use wrap: