Keep the condition tags but skip the target settings.
Quick unpaid promotion! Attend MadWorld for my session and many others. Meet and learn from top technical communicators.
We’ll start with a fresh project based on the Empty template which comes with Flare.
To keep it simple, we’ll use the Default condition tag set. But one of the nice things about having condition tag sets is there can be more than one. Since we aren’t going to touch the settings for these tags in the target, this is a situation when a separate set would make sense.
We can change the conditions to represent versions of a product. Periods are not allowed in the Condition Tag field. If you use periods or full stops (.) in version numbers you will have to find a different character for the tag. But you can still use the period in the text of the drop-down we will create in the topic.
Now we can create some content to which to apply the tags.
And apply the tags.
Here is the topic in the XML Editor with the conditions applied:
Now let’s look at those tags in the Text Editor.
Here is the first tagged paragraph. In the XML for the topic, the MadCap:conditions attribute holds the conditions. The condition is appended to the condition tag set name and a period symbol:
<p MadCap:conditions="Default.1-0">This is content for version 1-0.</p>
When there is more than one, the conditions are separated by commas.
<p MadCap:conditions="Default.1-0,Default.2-0">This is content for version 1-0 and 2-0.</p>
File that in your memory. Now let’s add the UI for the filter. We can create a snippet to hold the filter for topic reuse. The snippet will use a select element, the element’s children, and some attributes. Here is the snippet in the Text Editor.
We can’t see the UI for the snippet from the Text Editor or the XML Editor. But we can see a preview when we add the snippet.
There are two functions. The first, getElementsWithAttribute, is used by the other function, showHideVersion, to get all of the elements in the topic with the data-mc-conditions attribute. Remember MadCap:conditions in the topic XML? That becomes data-mc-conditions in the HTML5 output topics.
The showHideVersion function looks for the select element and gets the selected option. Then it loops through all of the elements with data-mc-conditions and shows or hides the elements based on whether the elements include the selected condition.
The last line of the script ensures the script runs when the page initially loads.
Let’s not forget to add the master page to the target.
At this point we are ready to build. Here again is how the output looks. You can select a version and only content tagged with that version appears.
Update: There is a follow-up post and sample which persists the original display value instead of toggling between none and block.