Formating text to be a hyperlink

Hello,

Im looking to format a piece of text in my content and if its found, to switch it to a link - but when using the example below. the link appears in my text like {a href"…"}Hello{/a} … so its replacing my < > symbols with { }.

Thanks in advance!

Side note - it’s also striping any HTML tags inputted by the WSWYG editor and formats the content into one big block - i guess I’ll have to manually insert the HTML to get these back?

Hey Jack, that’s a really interesting use case! I’d never tried that but you’re right that it seems like using the Get tag with its “normal” syntax (like <Get hello />) works correctly and renders your hyperlinked text, but for some reason when you use the syntax that puts the tag in the value of an attribute (like "{Get hello }") it doesn’t work and replaces the angle brackets with curly braces and outputs the HTML tags as a text string. I tried using a template variable too (<Set template=hello />) and it had the same behaviour. I assume the replace and with attributes are designed for replacing simple text strings, so that with attribute is interpreting <a href=... as a string and not as HTML code. I think this is the expected behaviour since Format replace is currently designed to replace one string with another. That being said, I can see the value in expanding this to allow it to replace a string with some HTML or even an entire template. I’ve added this feature request and I’ll let the devs look into the feasibility of this.

Regarding your side-note, if I understand correctly, you’re noticing the same behaviour as this forum user, right? If so, that feature/improvement request has been added and the devs are looking into addressing it.

Hello jack. I don’t know if this will actually help you or not but I came up with a hack that might do what you want, lols

Format for Jack

And the result is like this:

Format result

Hope that helps Mr. Carter:)

Huh, that’s an interesting idea @Sunskie! I just gave it a try to attempt consolidating that into a single line using replace_2 with_2 but it looks like you need to run the formatting twice at a minimum: once to add the HTML tag and once to swap the curly braces with angle brackets. So this would be a (very slightly) more efficient way of achieving that:

<Set hello>
  <a href="https://example.com/">hello</a>
</Set>

<Format replace="{" with="<" replace_2="}" with_2=">">
  <Field summary replace="hello" with="{Get hello}" />
</Format>

Still hacky, so we’ll see what the devs come back with to make it possible to work with tags and templates within Format replace instead of just text strings in a future update. Also just a quick tip: you guys might want to check out this post about formatting your code blocks in Discourse. A bit easier to work with than screenshots :stuck_out_tongue_winking_eye:

1 Like

Maybe off-topic but in case: what if you replace the characters by HTML entities?
< by &lt;
> by &gt;

1 Like
<Set hello>
  &lt;a href="https://example/help"&gt;Hello&lt;/a&gt;
</Set>

<Format replace="hello" with="{Get hello}" >hello </Format>

Like that?

Yes, like that, maybe the parser won’t interfer

Info: HTML Entities

Thanks for all the help everyone!

You should all pat yourselves on the back - great work.

Tangible is an incredible bit of kit!

game changer.

Jack

1 Like

I’m glad the solutions here are working for you! We’ll still have the devs look into the feasibility of allowing Format replace to work with markup/templates so I’ll post back here if we end up releasing that in a future update.

Thanks for the kind words about Loops & Logic! If you’re interested, we’re trying to bump our plugin’s rating up to 5 stars, so if you’re happy with the capabilities of the plugin and the support you’ve received, it’d mean the world for our small team if you’d consider adding that as a review on the WordPress repo. Good luck with your future L&L experiments!

1 Like