menu   UA Europe - Training & Consulting
UA Europe - Training & Consulting
UA Europe - Training & Consulting

Specialists in
User Assistance
& organisers of the
UA Europe Conference

Snippet Conditions and customised re-use in MadCap Flare

Published in ISTC Communicator, Winter 2016.

Introduction

Flare is marketed as a single-sourcing tool with many features that support re-use of content. Snippets represent one of the most powerful and popular of these features, and they enable you to re-use a chunk of content by reference in multiple topics, either within the same project or even (by using project linking) across multiple projects.

If you are a Flare user, you are probably already aware of the benefits of snippets over copy and paste, with all its inherent maintenance issues. But did you know that you can customise individual instances of the same snippet by using snippet conditions and snippet variables? This article considers the potential benefits of customising snippets in this way, and provides some tips and guidance on how to do it.

Snippet conditions

One way of customising snippets is to use snippet conditions, which have been supported within Flare as long as I can remember. These enable you to apply conditions within the source snippet, and then using the Properties of the topic into which the snippet has been inserted to specify which of these conditions will be included or excluded. In this way, two different topics can use the same snippet but display different conditional content within the snippet.

Why might you want to do this? Well, let's say that you have created a snippet containing a list of bank holidays in the UK marked up with three different conditions (England/Wales, Scotland, Northern Ireland) that enable it to be customised for each of the different member countries.

Screenshot showing bank holidays snippet

Let's also assume that you want to publish to a single target that covers the whole of the UK and that contains different sections for each of the individual countries.

After inserting the bank holidays snippet into a topic, you would use Topic Properties (Snippet Conditions tab) to ensure that the correct bank holidays for the current section are shown. For example, if the topic was within the section about Scotland you would Include the blue Scotland condition, which has the effect of filtering out all conditional content not tagged with the Scotland condition.

Screenshot showing Include Scotland condition

Snippet conditions on individual snippets

Flare 12 introduced the ability to include/exclude conditions for each individual instance of a snippet. This overrides what may have been specified within the containing Topic Properties. This would be useful, for example, if you wanted to include a separate list of bank holidays for each of the member countries within a single topic. You would do this by inserting the same snippet four times, right-clicking on each instance to select Snippet Conditions, and then including the appropriate condition.

Screenshot showing Select Snippet Conditions

Note that if you have excluded a condition within the Target settings, you cannot then successfully include that condition using a Snippet Condition. This is one of the rare cases of "Exclude" trumping "Include" within Flare.

Snippet Variables

It has always been possible to override the definitions of variables at the target level, and I often cite this as one of my favourite features of Flare. With the release of Flare 12, it became possible to override the definitions of variables within snippets either at the enclosing topic level or at individual snippet level. Using this technique, we could include a country variable in the heading within our bank holidays snippet, and then select the appropriate variable definition for each instance of the snippet.

Screenshot showing Select variable definition

This is a neater solution than typing all four country names into the snippet and using conditions to filter out all but one of them.

Further reading

There is detailed information within Flare's Help about snippet conditions and about overriding variables definitions in snippets.