Filter Content

THESE PAGES ARE STILL UNDER CONSTRUCTION AND DO NOT NECESSARELY REFLECT THE CURRENT VERSION OF TÓPICO

In this tutorial, you'll learn how you can come up with a basic filtering technique for publishing to two different audiences.

Maybe you'd like to single source a small publication for different audiences. Let's pretend this would be a small collection of policies and procedures to be published for "managers" and "technicians".

Tópico makes this kind of filtering easy to setup with the use of a collection wide template parameter. This tutorial shows you how you could proceed with such a scenario.

Try it yourself!

Tip

You can try this scenario for yourself with the feature workshop collection.

  1. Download and open and publish the features collection; (you will need the professional version of Tópico)
  2. Navigate to the filtered content topic (wich is published for managers);
  3. Close the publication;
  4. Select the Collection tab;
  5. Set the "audience" parameter to technicians;
  6. Save and publish the collection;
  7. Navigate to the filtered content topic (wich is now published for technicians).

Note: Update ths section and add a link to download the Features collection.

Design the base scenario

You would like your topics to contain the following sentence, in two versions:

"In this procedure, the manager is required to do management stuff."

"In this procedure, the technician is expected to do technical stuff."

In the above sentences, text in italic should be filtered to output one ot the other version.

Define the markup

To be able to output these two versions, you will makup your text as follow:

Example

In this procedure, the <span class="manager">manager</span> <span class="technician">technician</span> is <span class="manager">required to do management stuff</span> <span class="technician>expected to do technical stuff</span>.

Tip

Setting up some specific editing stylesheet selector for the above tag is always a good idea.

Set up your styles list

As you did in the Add a new semantic tag tutorial, the best way to work with this setup is to add the two styles to your custom styles drop down list.

To add these two styles to the drop down list, follow these steps:

  1. Right click on the Styles button above the editor;
  2. From the popup menu, select the file styles.custom.xml;
  3. Locate the last group of styles in this file;
    The file is structured like this:
    - The top element is styles
    - There are multiple group of style elements within the top styles tag
  4. Add the two style elements that are found below the last group;
  5. Save and close the file;
  6. Left click on the Styles button above the editor and select styles.custom;
XML
<style>
 <name xml:lang="en">Manager (div)</name>
 <name xml:lang="fr">Gestionnaire (div)</name>
 <description xml:lang="en"/>
 <description xml:lang="fr"/>
 <elt>div</elt>
 <attr>
  <name>class</name>
  <value>manager</value>
 </attr>
</style>
 <style>
 <name xml:lang="en">Technician (div)</name>
 <name xml:lang="fr">Technicien (div)</name>
 <description xml:lang="en"/>
 <description xml:lang="fr"/>
 <elt>div</elt>
 <attr>
  <name>class</name>
  <value>technician</value>
 </attr>
</style>

Now that the styles are defined in this file, using it will only be a matter of selecting it from a drop down list, which is much easier that creating the span elements manually each time you want to use it. Creating styles is discussed a bit further on the XStandard web site.

Tip

While your at it, you might want to define <div> elements with the "manager" and "technician" classes so you can insert block elements that you can also filter.

Ajusting the display of these elements in the editing stylesheet is also an option you might want to look at. You can setup the editing stylesheet differently that the publishing one.

Setting up the filtering criteria

For the template to know which version you want to publish, you need a way to let it know about it. This is done through a collection wide template parameter.

To define a collection wide template parameter:

  1. Navigate to the Collection tab;
  2. In the template parameters grid, enter "audience" (without the quotes) as the parameter name and "manager" as the parameter value;
  3. Save your collection.

Add the audience parameter to the template

In your publishing template, you'll have to define the newly created parameter and create specific templates to trap your do the actual filtering.

For your template to use the audience parameter, you need to define it at the top of the template.

  1. Make sure you're on the Collection tab;
  2. Click on the small e button at the left of the Template drop down list;
  3. From the popup menu, select the template that's shown in the drop down list;
  4. If prompted for a program to open the file, choose Notepad;
  5. Add the following parameter definition below the line importing the file import.xsl;
    <xsl:param name="audience" select="manager"/>
    You can add this parameter above or velow all the other, as long as it's with the rest of the parameters;
  6. Save the file (and leave it open for the next few steps in the tutorial);

Your custom parameter is now ready to be used.

Filter content with the audience parameter

To filter content with the audience parameter, you'll use a more specific template for the span element.

At the bottom of the file, just above the last line (</xsl:stylesheet>), insert the following template:

XSLT
<!-- div manager/technician template -->
<xsl:template match="xhtml:div" mode="import">
  <xsl:choose>
   <!--first check if a technician or manager class attribute is present-->
   <xsl:when test="contains(@class,'technician') or contains(@class,'manager')">
    <xsl:choose>
     <!-- filter manager -->
     <xsl:when test="$audience = 'manager'">
      <!-- remove technician -->
      <xsl:if test="contains(@class,'technician')=false">
       <!-- process if not technician -->
       <xsl:apply-templates select="@*|node()" mode="import"/>
      </xsl:if>
     </xsl:when>
     <!-- filter technician -->
     <xsl:when test="$audience = 'technician'">
      <!-- remove manager -->
      <xsl:if test="contains(@class,'manager')=false">
       <!-- process if not manager -->
       <xsl:apply-templates select="@*|node()" mode="import"/>
      </xsl:if>
     </xsl:when>
    <!-- filter none -->
    <xsl:otherwise>
     <xsl:element name="{name()}">
      <xsl:apply-templates select="@*|node()" mode="import"/>
     </xsl:element>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:when>
 <!-- do nothing if a technician or manager class attribute is not present -->
 <xsl:otherwise>
  <xsl:element name="{name()}">
   <xsl:apply-templates select="@*|node()" mode="import"/>
  </xsl:element>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>	

Now when the parameter has a value of "manager", you'll get this output:

"In this procedure, the manager is required to do management stuff."

When the parameter has a value of "technician", you'll get this output:

"In this procedure, the technician is expected to do technical stuff."

About the above template

The first thing to note about the above template is that it uses the mode="import" attribute since the main template also use this mode. Removeing this attribute, or setting it to another value, would skip this template altogether.

This template basically checks the value of the audience parameter and output the proper content like this:

  • If the audience parameter is equal to "manager", publish this element if it's class attribute does not contain "technician".
  • If the audience parameter is equalt to "technician", publish this element if it's class attribute does not contain "manager".

This effectively removes the alternate content without affecting the output of other <span/> elements.

If the audience parameter is not set, all spans are published in the output files.

 

THESE PAGES ARE STILL UNDER CONSTRUCTION AND DO NOT NECESSARELY REFLECT THE CURRENT VERSION OF TÓPICO

68 / 194