Snippets vs Variables - Best Practices?

This forum is for Single-Sourcing your Flare content to multiple outputs.
Post Reply
CoolLime
Propeller Head
Posts: 41
Joined: Mon Apr 18, 2016 6:50 am
Location: Toronto, Canada

Snippets vs Variables - Best Practices?

Post by CoolLime »

I know there have been a handful of discussions about snippets vs variables here in the forum in the past, but I am still trying to discover a good basis for deciding one or the other. Does anyone out there have a decision process for choosing to snippetize or variable-ify some piece of content or another?
devjoe
Sr. Propeller Head
Posts: 337
Joined: Thu Jan 23, 2014 1:43 pm

Re: Snippets vs Variables - Best Practices?

Post by devjoe »

Use a variable when you are specifying a short bit of unformatted text such as the name of a product, product feature, or company.
Use a variable when you are specifying text that might get included within a TOC entry, the destination of a link, or any similar place other than displayed topic text.

Use a snippet when the included content contains formatting or tags of any sort, including anything that is long enough that it needs to exist as its own paragraph, or multiple paragraphs.
CoolLime
Propeller Head
Posts: 41
Joined: Mon Apr 18, 2016 6:50 am
Location: Toronto, Canada

Re: Snippets vs Variables - Best Practices?

Post by CoolLime »

So would you use variables, for example, for URLs?
Nita Beck
Senior Propellus Maximus
Posts: 3667
Joined: Thu Feb 02, 2006 9:57 am
Location: Pittsford, NY

Re: Snippets vs Variables - Best Practices?

Post by Nita Beck »

CoolLime wrote:So would you use variables, for example, for URLs?
I regularly put URLs and email links in individual snippets. If I were to make them variables, they wouldn't have any "links" behind them.
Nita
Image
RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
CoolLime
Propeller Head
Posts: 41
Joined: Mon Apr 18, 2016 6:50 am
Location: Toronto, Canada

Re: Snippets vs Variables - Best Practices?

Post by CoolLime »

Nita Beck wrote:
CoolLime wrote:So would you use variables, for example, for URLs?
I regularly put URLs and email links in individual snippets. If I were to make them variables, they wouldn't have any "links" behind them.
That's strange, because somehow I have URLs as variables and they do have links... I don't know how that is possible then
CoolLime
Propeller Head
Posts: 41
Joined: Mon Apr 18, 2016 6:50 am
Location: Toronto, Canada

Re: Snippets vs Variables - Best Practices?

Post by CoolLime »

Nita Beck wrote:
CoolLime wrote:So would you use variables, for example, for URLs?
I regularly put URLs and email links in individual snippets. If I were to make them variables, they wouldn't have any "links" behind them.
I think MadCap has the MadCap:variable.URL style and when I make a URL into a variable, when I insert that variable it automatically uses that style. Or do I have this wrong?
Nita Beck
Senior Propellus Maximus
Posts: 3667
Joined: Thu Feb 02, 2006 9:57 am
Location: Pittsford, NY

Re: Snippets vs Variables - Best Practices?

Post by Nita Beck »

CoolLime wrote:I think MadCap has the MadCap:variable.URL style and when I make a URL into a variable, when I insert that variable it automatically uses that style. Or do I have this wrong?
Couldn't say. I've been using Flare since version 1 so maybe what you write about was some new feature somewhere along the way that I didn't pay attention to as I continued to follow my usual practice. I'll have to go check it out.

FWIW, I'm not talking about styling. I'm talking about the underlying links, plus by putting URLs in snippets, I get to set things such as the target window and other things related to the link themselves.
Nita
Image
RETIRED, but still fond of all the Flare friends I've made. See you around now and then!
CoolLime
Propeller Head
Posts: 41
Joined: Mon Apr 18, 2016 6:50 am
Location: Toronto, Canada

Re: Snippets vs Variables - Best Practices?

Post by CoolLime »

Nita Beck wrote:
CoolLime wrote:I think MadCap has the MadCap:variable.URL style and when I make a URL into a variable, when I insert that variable it automatically uses that style. Or do I have this wrong?
Couldn't say. I've been using Flare since version 1 so maybe what you write about was some new feature somewhere along the way that I didn't pay attention to as I continued to follow my usual practice. I'll have to go check it out.

FWIW, I'm not talking about styling. I'm talking about the underlying link, plus by putting URLs in snippets, I get to set things such as the target window and other things related to the link themselves.
Well, in a PDF output these links work--so I guess they must be there. That said, are there are any other reasons to use a snippet over a variable for this purpose?
NorthEast
Master Propellus Maximus
Posts: 6359
Joined: Mon Mar 05, 2007 8:33 am

Re: Snippets vs Variables - Best Practices?

Post by NorthEast »

CoolLime wrote:Well, in a PDF output these links work--so I guess they must be there.
The variable is not a hyperlink.

The link works in a PDF because that's a feature of Adobe Reader - it detects URLs in plain text, and converts them to hyperlinks.
In Adobe Reader, select Edit > Preferences, select General, then deselect Create links from URLs.
Now your links will be plain text, and won't work - so the links are not in the PDF itself.

You can test the "create links" setting by just typing a URL in plain text in your Flare topic, then viewing the PDF. It doesn't have to be in a variable.
devjoe
Sr. Propeller Head
Posts: 337
Joined: Thu Jan 23, 2014 1:43 pm

Re: Snippets vs Variables - Best Practices?

Post by devjoe »

Nita Beck wrote:
CoolLime wrote:So would you use variables, for example, for URLs?
I regularly put URLs and email links in individual snippets. If I were to make them variables, they wouldn't have any "links" behind them.
What I am talking about is when you have a link that needs to have a different destination in different targets. The code for the link includes the variable as the destination for the link. The variable contains the URL. This avoids making multiple versions of the link or the content containing the link side-by-side.
AlexFox
Sr. Propeller Head
Posts: 149
Joined: Thu Oct 19, 2017 1:56 am

Re: Snippets vs Variables - Best Practices?

Post by AlexFox »

You could use a variable as a link if desired:

Code: Select all

<a href="[%=Variables.URL%]">[%=Variables.URL_Display_Text%]</a>
CoolLime
Propeller Head
Posts: 41
Joined: Mon Apr 18, 2016 6:50 am
Location: Toronto, Canada

Re: Snippets vs Variables - Best Practices?

Post by CoolLime »

Dave Lee wrote:
CoolLime wrote:Well, in a PDF output these links work--so I guess they must be there.
The variable is not a hyperlink.

The link works in a PDF because that's a feature of Adobe Reader - it detects URLs in plain text, and converts them to hyperlinks.
In Adobe Reader, select Edit > Preferences, select General, then deselect Create links from URLs.
Now your links will be plain text, and won't work - so the links are not in the PDF itself.

You can test the "create links" setting by just typing a URL in plain text in your Flare topic, then viewing the PDF. It doesn't have to be in a variable.
I learned something here. But then what is MadCap|variable.URL then?
AlexFox
Sr. Propeller Head
Posts: 149
Joined: Thu Oct 19, 2017 1:56 am

Re: Snippets vs Variables - Best Practices?

Post by AlexFox »

CoolLime wrote:I learned something here. But then what is MadCap|variable.URL then?
That's just a custom class called "URL" for variables. Presumably it's just used to style plain text variables as a clickable URL would be.
CoolLime
Propeller Head
Posts: 41
Joined: Mon Apr 18, 2016 6:50 am
Location: Toronto, Canada

Re: Snippets vs Variables - Best Practices?

Post by CoolLime »

AlexFox wrote:That's just a custom class called "URL" for variables. Presumably it's just used to style plain text variables as a clickable URL would be.
Understood.
Post Reply