Snippet Variables in Hyperlinks

This forum is for Single-Sourcing your Flare content to multiple outputs.

Snippet Variables in Hyperlinks

Postby TimHowd on Tue Feb 23, 2021 2:59 pm

Hi friends!

I am building a "catalog" style page that allows users to click a link on a catalog entry and have the request ticket filled out based on variable query parameters. Naturally, as the catalog grows and changes, I wanted to create a Snippet for the request link, which I can just drop in an set to different variable definitions.

My Snippet code looks (basically) like this:

Code: Select all
<a class="ctabutton" href="https://www.mywebsite.com/request?ref=[%=CatalogEntry.CatalogRef%]>
Purchase <MadCap:variable name="CatalogEntry.CatalogRef" />
</a>


This variable set has one variable with a zillion variable definitions. I figured that I could be super clever and use the Snippet Variables... feature to change the variable definition and the query parameter.

When I publish it (to an HTML5 Target), however, choosing the variable definition works for the display text variable (<MadCap:variable name="CatalogEntry.CatalogRef" />) but for the URL, it takes the variable definition set in the Target.

So on my web page, it looks like this:
  • Purchase REF-001
  • Purchase REF-002
  • Purchase REF-003

But the URLs all look like this (took it out of Code to bold the variables):

<a class="ctabutton" href="https://www.mywebsite.com/request?ref=REF-001">Purchase REF-001[/b"</a>
<a class="ctabutton" href="https://www.mywebsite.com/request?ref=[b]REF-001
">Purchase REF-002</a>
<a class="ctabutton" href="https://www.mywebsite.com/request?ref=REF-001">Purchase REF-003</a>

Does anyone have any thoughts on how I can get around this so that I can re-use this Snippet and the URL changes along with the display text variable?

Thank you!
Last edited by TimHowd on Wed Feb 24, 2021 7:24 am, edited 1 time in total.
TimHowd
Jr. Propeller Head
 
Posts: 6
Joined: Fri Sep 06, 2019 1:07 pm

Re: Snippet Variables in Hyperlinks

Postby Dave Lee on Wed Feb 24, 2021 3:07 am

Your example works fine for me, so not sure what to suggest.

I did notice your code examples are missing a " after the href, but if that's in your actual code then I'm pretty sure you'd notice as it's invalid XML.
Dave Lee
Master Propellus Maximus
 
Posts: 5961
Joined: Mon Mar 05, 2007 8:33 am
Location: UK

Re: Snippet Variables in Hyperlinks

Postby TimHowd on Wed Feb 24, 2021 7:25 am

Thank you Dave! That was just a typo on my part here - I edited the post to correct it.

So to confirm what you said: when you do what I suggested, you could actually get the Snippet Variables to apply to both the hyperlink (in the code) and the in-text variable?
TimHowd
Jr. Propeller Head
 
Posts: 6
Joined: Fri Sep 06, 2019 1:07 pm

Re: Snippet Variables in Hyperlinks

Postby Dave Lee on Wed Feb 24, 2021 9:20 am

TimHowd wrote:Thank you Dave! That was just a typo on my part here - I edited the post to correct it.

So to confirm what you said: when you do what I suggested, you could actually get the Snippet Variables to apply to both the hyperlink (in the code) and the in-text variable?


Yep, I've got the same variable in both the href and link text, and it works fine.
And when setting variables at the topic or target level, variables set at the snippet level are correctly taking precedence.
Dave Lee
Master Propellus Maximus
 
Posts: 5961
Joined: Mon Mar 05, 2007 8:33 am
Location: UK


Return to Single-Sourcing

Who is online

Users browsing this forum: No registered users and 5 guests