{"id":355,"date":"2013-01-24T01:38:26","date_gmt":"2013-01-24T01:38:26","guid":{"rendered":"http:\/\/tregner.com\/flare-blog\/?p=355"},"modified":"2013-01-28T18:38:34","modified_gmt":"2013-01-28T18:38:34","slug":"version-filters-in-html5-output","status":"publish","type":"post","link":"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/","title":{"rendered":"Version Filters in HTML5 Output"},"content":{"rendered":"<p><i style=\"line-height: 1.714285714; font-size: 1rem;\">Keep the condition tags but skip the target settings.<\/i><\/p>\n<p>Quick unpaid promotion! Attend <a href=\"http:\/\/www.madcapsoftware.com\/events\/madworld\/\">MadWorld<\/a> for my session and many others. Meet and learn from top technical communicators.<\/p>\n<p><a title=\"sample project\" href=\"http:\/\/tregner.com\/example-projects\/VersionTest1.flprjzip\">sample project<\/a><\/p>\n<p><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/filter-in-flare-html5-topic\/\" rel=\"attachment wp-att-362\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-362\" alt=\"filter-in-flare-html5-topic\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/filter-in-flare-html5-topic.png\" width=\"555\" height=\"379\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/filter-in-flare-html5-topic.png 555w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/filter-in-flare-html5-topic-300x204.png 300w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/a><\/p>\n<p><img style=\"line-height: 1.714285714; font-size: 1rem;\" title=\"filter-in-flare-html5-topic\" alt=\"\" src=\"file:\/\/\/C:\/Users\/TomTr\/AppData\/Local\/Temp\/msohtmlclip1\/01\/clip_image002.jpg\" \/>You can apply conditions to your Flare content and use those conditions to create a version filter in your Flare HTML5 output. The main ingredients are a select element and a little JavaScript. Here\u2019s how.<\/p>\n<p>We\u2019ll start with a fresh project based on the Empty template which comes with Flare.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/flare-with-empty-project\/\" rel=\"attachment wp-att-364\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-364\" alt=\"flare-with-empty-project\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/flare-with-empty-project.png\" width=\"628\" height=\"431\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/flare-with-empty-project.png 628w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/flare-with-empty-project-300x205.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/flare-with-empty-project-624x428.png 624w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><\/p>\n<p>To keep it simple, we\u2019ll 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\u2019t going to touch the settings for these tags in the target, this is a situation when a separate set would make sense.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/default-conditions\/\" rel=\"attachment wp-att-361\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-361\" alt=\"default-conditions\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/default-conditions.png\" width=\"593\" height=\"121\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/default-conditions.png 593w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/default-conditions-300x61.png 300w\" sizes=\"(max-width: 593px) 100vw, 593px\" \/><\/a><\/p>\n<p>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.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/new-conditions\/\" rel=\"attachment wp-att-366\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-366\" alt=\"new-conditions\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/new-conditions.png\" width=\"593\" height=\"143\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/new-conditions.png 593w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/new-conditions-300x72.png 300w\" sizes=\"(max-width: 593px) 100vw, 593px\" \/><\/a><\/p>\n<p>Now we can create some content to which to apply the tags.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/topic-no-conditions-or-filter\/\" rel=\"attachment wp-att-371\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-371\" alt=\"topic-no-conditions-or-filter\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/topic-no-conditions-or-filter.png\" width=\"593\" height=\"421\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/topic-no-conditions-or-filter.png 593w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/topic-no-conditions-or-filter-300x212.png 300w\" sizes=\"(max-width: 593px) 100vw, 593px\" \/><\/a><\/p>\n<p>And apply the tags.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/adding-condition-to-paragraph\/\" rel=\"attachment wp-att-359\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-359\" alt=\"adding-condition-to-paragraph\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/adding-condition-to-paragraph.png\" width=\"628\" height=\"431\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/adding-condition-to-paragraph.png 628w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/adding-condition-to-paragraph-300x205.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/adding-condition-to-paragraph-624x428.png 624w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><\/p>\n<p>Here is the topic in the XML Editor with the conditions applied:<\/p>\n<p><a style=\"font-size: 1rem; color: #0f3647;\" href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/topic-with-conditions\/\" rel=\"attachment wp-att-372\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-372\" alt=\"topic-with-conditions\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/topic-with-conditions.png\" width=\"593\" height=\"421\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/topic-with-conditions.png 593w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/topic-with-conditions-300x212.png 300w\" sizes=\"(max-width: 593px) 100vw, 593px\" \/><\/a><\/p>\n<p>Now let\u2019s look at those tags in the Text Editor.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/topic-with-conditions-in-text-editor\/\" rel=\"attachment wp-att-373\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-373\" alt=\"topic-with-conditions-in-text-editor\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/topic-with-conditions-in-text-editor.png\" width=\"628\" height=\"431\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/topic-with-conditions-in-text-editor.png 628w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/topic-with-conditions-in-text-editor-300x205.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/topic-with-conditions-in-text-editor-624x428.png 624w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><\/p>\n<p>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>\n<pre>&lt;p MadCap:conditions=\"Default.1-0\"&gt;This is content for version 1-0.&lt;\/p&gt;<\/pre>\n<p>When there is more than one, the conditions are separated by commas.<\/p>\n<pre>&lt;p MadCap:conditions=\"Default.1-0,Default.2-0\"&gt;This is content for version 1-0 and 2-0.&lt;\/p&gt;<\/pre>\n<p>File that in your memory. Now let\u2019s 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\u2019s children, and some attributes. Here is the snippet in the Text Editor.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/snippet-for-filter\/\" rel=\"attachment wp-att-369\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-369\" alt=\"snippet-for-filter\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/snippet-for-filter.png\" width=\"652\" height=\"288\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/snippet-for-filter.png 652w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/snippet-for-filter-300x132.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/snippet-for-filter-624x275.png 624w\" sizes=\"(max-width: 652px) 100vw, 652px\" \/><\/a><\/p>\n<p>There is an id attribute on the select element so the JavaScript can find the filter. The select element fires a JavaScript every time the the selection is changed. Here is the snippet in the topic:<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/snippet-in-topic\/\" rel=\"attachment wp-att-370\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-370\" alt=\"snippet-in-topic\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/snippet-in-topic.png\" width=\"555\" height=\"421\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/snippet-in-topic.png 555w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/snippet-in-topic-300x227.png 300w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/a><\/p>\n<p>We can\u2019t 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.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/insert-snippet-for-filter\/\" rel=\"attachment wp-att-365\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-365\" alt=\"insert-snippet-for-filter\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/insert-snippet-for-filter.png\" width=\"628\" height=\"487\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/insert-snippet-for-filter.png 628w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/insert-snippet-for-filter-300x232.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/insert-snippet-for-filter-624x483.png 624w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><\/p>\n<p>The JavaScript will look at the selected option and show or hide tagged elements based on the selection. Here is the JavaScript in Flare\u2019s Text Editor:<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/show-hide-javascript\/\" rel=\"attachment wp-att-368\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-368\" alt=\"show-hide-javascript\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/show-hide-javascript.png\" width=\"628\" height=\"420\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/show-hide-javascript.png 628w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/show-hide-javascript-300x200.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/show-hide-javascript-624x417.png 624w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n<p>The last line of the script ensures the script runs when the page initially loads.<\/p>\n<p>We can reference the JavaScript in the master page. There is no default master page in the Empty template. We can base the new master page on the MasterPage.flmsp Factory Template. The script will go after the body element in the master page so we will add it through the Text Editor. Note the relative path to the file.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/script-reference-in-master-page\/\" rel=\"attachment wp-att-367\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-367\" alt=\"script-reference-in-master-page\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/script-reference-in-master-page.png\" width=\"628\" height=\"249\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/script-reference-in-master-page.png 628w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/script-reference-in-master-page-300x118.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/script-reference-in-master-page-624x247.png 624w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><\/p>\n<p>Let\u2019s not forget to add the master page to the target.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/adding-master-page-to-target\/\" rel=\"attachment wp-att-360\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-360\" alt=\"adding-master-page-to-target\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/adding-master-page-to-target.png\" width=\"628\" height=\"433\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/adding-master-page-to-target.png 628w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/adding-master-page-to-target-300x206.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/adding-master-page-to-target-624x430.png 624w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><\/p>\n<p>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.<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/filter-in-flare-html5-topic-drop-down-not-open\/\" rel=\"attachment wp-att-363\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-363\" alt=\"filter-in-flare-html5-topic-drop-down-not-open\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/filter-in-flare-html5-topic-drop-down-not-open.png\" width=\"555\" height=\"379\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/filter-in-flare-html5-topic-drop-down-not-open.png 555w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/filter-in-flare-html5-topic-drop-down-not-open-300x204.png 300w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/filter-in-flare-html5-topic\/\" rel=\"attachment wp-att-362\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-362\" alt=\"filter-in-flare-html5-topic\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/filter-in-flare-html5-topic.png\" width=\"555\" height=\"379\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/filter-in-flare-html5-topic.png 555w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/filter-in-flare-html5-topic-300x204.png 300w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/a><\/p>\n<p>Now you can filter on a single condition in a topic from the published output. In this example and sample, the content must be tagged to appear. But you don&#8217;t have to limit yourself to that behavior with your JavaScript. What kind of filter behavior would you expect to see in a version filter? Let me know in the comments.<\/p>\n<p><a style=\"line-height: 1.714285714; font-size: 1rem;\" title=\"sample project\" href=\"http:\/\/tregner.com\/example-projects\/VersionTest1.flprjzip\">sample project<\/a><\/p>\n<p>Update: There is a follow-up <a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output-persisting-display-instead-of-toggling\/\" target=\"_blank\">p<\/a><span style=\"line-height: 1.714285714; font-size: 1rem;\"><a href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output-persisting-display-instead-of-toggling\/\" target=\"_blank\">ost<\/a> and <a href=\"http:\/\/tregner.com\/example-projects\/VersionTest2.flprjzip\" target=\"_blank\">sample<\/a>\u00a0which persists the original display value instead of toggling between none and block.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. sample project You can apply conditions to your Flare content and use those conditions to create a version filter in your Flare HTML5 output. The main ingredients are&hellip; <a class=\"more-link\" href=\"https:\/\/tregner.com\/flare-blog\/version-filters-in-html5-output\/\">Continue reading <span class=\"screen-reader-text\">Version Filters in HTML5 Output<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[51,53,49,5,50,52],"_links":{"self":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/355"}],"collection":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/comments?post=355"}],"version-history":[{"count":21,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/355\/revisions"}],"predecessor-version":[{"id":401,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/355\/revisions\/401"}],"wp:attachment":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/media?parent=355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/categories?post=355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/tags?post=355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}