Add text to page template based on project locale

A customer was producing output for distribution in several different languages. The solution was to create multiple Express product projects (based on the same stationery), each with a different Locale setting in the Format Settings, and each with a different collection of documents. Additionally, she was concerned that some of the topics were authored only in English, so she wanted to add a line of text to the top of certain pages to notify a foreign-language user that the content was available only in English.


The solution was to modify the page template and the associated XSL with a conditional statement that would add the desired text based on the placement of PageStyle markers and the value of the project's locale setting. This was the full response:

As I understand it, you want to generate output for which only some of the content pages include an extra line at the top that is the same for each and independent of the source content.

Rather than using multiple page templates, it's better to just add some additional information to the existing page template that will only be included in the output page if certain requirements are met. That is, you can add an "English" PageStyle marker to each of the source pages that should display this message, and then add a conditional line in the page template which checks the value of that PageStyle and adds the necessary line of text only if the appropriate marker is found.

So, try these steps:

1. Perform an override on Page.asp. Once it is copied into the appropriate folder in your project directory, open it with a text editor.

2. Locate this line in the page template: <hr wwpage:condition="header-exists" align="left" />

Below that line, the main content of each page is inserted. Since you want to add your message to the top of the page, you likely want to insert that text here.

3. Add the following text (modifying it for content and style to suit your needs):

<div wwpage:condition="English" style="text-align:center; font: bold 12pt 'arial,verdana,sans-serif'; background-color: #FFFFCC;">
This page is currently available in English only.
</div>

4. Save and close Page.asp.

Next, you'll want to create the code logic that will decide whether to insert that message on a particular page. The file responsible for processing the page template is called pages.xsl, and it is located in the ePublisher Pro installation directory, here: ePublisher Pro\Formats\WebWorks Help 5.0\Transforms\

1. Perform an override on pages.xsl.

2. When it has been copied into your project directory, open it with a text- or XSL-editing application.

3. Locate this line:

<xsl:variable name="VarInitialConditionsAsXML">

4. Below that, add the following:

<!-- English-only -->
<!--                    -->
<xsl:variable name="VarLocale" select="wwprojext:GetFormatSetting('locale', 'en')" />
<xsl:if test="(string-length($VarLocale) &gt; 0) and ($VarLocale != 'en')">
 <xsl:if test="contains(wwstring:ToLower($ParamSplit/@stylename),'english')">
  <wwpage:Condition name="English" />
  </xsl:if>
</xsl:if>

5. Save and close pages.xsl.

6. Save your project, update your stationery, and regenerate output to apply the changes.

So, in your source documents, you'll insert a PageStyle marker called "English" on each page that is only available in English. If you have used a different value for the marker text, just change the value in the "$ParamSplit/@stylename" line of the code above. When you generate output, ePublisher will check the project's Locale setting. If it is set to something other than "en" (English), then it will check the name of the PageStyle, as defined by the marker. If a marker exists, and the text is "English" (or "english"), then the "English" condition will evaluate to True. If that condition is true, then the DIV placed in Page.asp will be included in the HTML file generated for that content page. A line will be inserted at the top of the page notifying the user that the page is only available in English.

Once again, to summarize: the added line will only be visible on the pages for which an English PageStyle marker has been inserted, and only in projects based on this stationery for which the locale (in Format Settings) is set to something other than English.


CategorySolutionsOverrides CategorySolutionsLocalization

LaurenLever/@Solutions/Overrides/Locale to page template (last edited 2009-06-02 20:16:47 by LaurenLever)