Using Variables with Find/Replace in Flare

This one is a pret­ty sim­ple trick and, to be hon­est, one that a lot of folks prob­a­bly fig­ured out soon­er than I did. With just a lit­tle bit of work, you can eas­i­ly replace oft-used words or phras­es in your Flare project with a vari­able. This is espe­cial­ly use­ful if you find your­self writ­ing ear­ly on in the devel­op­ment process where some ter­mi­nol­o­gy of fea­tures or a prod­uct inter­face are sub­ject to change.

Or, if you’re like me and you just don’t know what the hell such-and-such thing is called and the devel­op­ment team has yet to answer your e‑mail ask­ing because they’re too busy for­ward­ing it to every­one else in the com­pa­ny who’ll get a good laugh out of the ridicu­lous­ly sil­ly ques­tion. Okay, that has­n’t actu­al­ly hap­pened (except for the part about me not know­ing what some­thing is actu­al­ly called). At least not that I’m aware of.

So, here are the steps for find­ing all the instances of a term and replac­ing it with a variable:

  1. Cre­ate a Vari­able in the MyVarables set.

    Note: It’s good prac­tice to use camel nota­tion when nam­ing your vari­able. Keep it short, but make it some­thing you can eas­i­ly iden­ti­fy (vari­ables don’t have den­tal records and teeth and such in the event of a seri­ous acci­dent). And be con­sis­tent in how you name things!

  2. Launch the Find and Replace pan­el by select­ing Edit > Find and Replace > Find and Replace from the menu bar, or just press Ctrl + F.
  3. Enter the text you wish to sub­sti­tute with a your new vari­able in the Find What field. Under the options sec­tion, select (whole project) for the Find In: field, Top­ics for File Types, and make sure the option for Find in source code is cleared (though we’ll use that option in a moment).
  4. Click the Start but­ton to locate the first instance of the text.
  5. The searched-for text will be select­ed for you in the XML edi­tor with­in a top­ic file. Click the top­ic’s tab along the edi­tor win­dow just to make that part of the pro­gram win­dow active. Now, select Insert > Vari­able… from the menu bar to open the Vari­ables dialog.
  6. Select the MyVari­ables set and then the vari­able you’ll be using to replace this par­tic­u­lar text with. Click the OK button.
  7. Now, you need to get the actu­al markup for this vari­able. The fastest way I know to do so is click the Locate in Con­tent Explor­er but­ton in the Stan­dard tool­bar. Then, with the top­ic file now select­ed, right click and select Open With > Inter­nal Text Edi­tor. Now, hunt around until you locate the vari­able tag. It looks like this:

    <MadCap:variable name="MyVariables.SuchAndSuch" />

    Select and copy this entire tag.

    Note: You can also use the Send To menu but­ton, also locat­ed on the stan­dard tool­bar. It’s the one that looks like an enve­lope and that you prob­a­bly thought was just for e‑mailing a file. How­ev­er, it will actu­al­ly open up the cur­rent file in an exter­nal pro­gram, includ­ing your handy text edi­tor (I use TextPad).

  8. Now, back in the Find and Replace pan­el, this is what you’ll paste into the Replace with: field. But now you’re going to make sure that the Find in source code option is now selected.
  9. Click the Start but­ton again (you changed the options since you last did so). Use the Replace and Find Next but­tons to swap out the text with the vari­able markup one by one.

A Note of Caution

You’re going to be replac­ing text in the source markup here so be care­ful. I strong­ly urge you to not use the Replace In All Files but­ton. It’s fast but it’s also risky. You’ll replace any instance of the text; any­where: key­words, etc. You might find your­self putting a vari­able tag where it real­ly does­n’t belong. For­tu­nate­ly, Flare will like­ly just give you a gen­tle scold­ing and ignore your sil­ly lit­tle non­sense. But, you might just find a loop­hole you wish you had­n’t. It’s best to do this one-at-a-time, even if that takes a while.

Ide­al­ly, Mad­Cap would add an option in the the Replace With field to just select one of your vari­ables from there. This way, you don’t have to Find/Replace in source code and run the risk of doing some­thing unin­tend­ed (hope­ful­ly they’d han­dle all that under the hood). But until then, only replace what you are sure is con­tent mate­r­i­al and not any­thing else.

Extend This Trick

Now, you can also use this lit­tle trick for find­ing and replac­ing oth­er code, so you could add a par­tic­u­lar style to any instance of a phrase. Ex: replace “OK but­ton” with “<strong>OK</strong> but­ton”. I’ve yet to find a lim­it to the num­ber of char­ac­ters avail­able in the Find and Replace field, but I sus­pect it’s prob­a­bly around 256 or so. I don’t think you’ll be replac­ing A Tale of Two Cities with War and Peace using this.

Fur­ther, you can use reg­u­lar expres­sion for — well — any­thing that you just about think of, I sup­pose. You can also use wild­cards which though not as sexy as RegEx are still quite use­ful when just doing text search. If you’re just look­ing for any instance of noun — plur­al or sin­gu­lar; RegEx might be swat­ting flies with tanks.