Variables - Conditional per Page

Description

Customer would like variables to be emitted only if defined. This requires adding <wwpage:Condition> elements.

Additionally, customer would like for variables to be restricted to "per page" definitions rather than being defined globally for the project group.

Conditions for Variables

Great question Arron!

You make a good point here. We don't provide an easy way to test for the presence of a variable.

However, if you're up for a bit of XSL fun, you can get this working by creating an override to "Transforms\pages.xsl".

By default, page variables are calculated in the replacements code segment as follows:

There are actually two operations going on here:

1. Determine variable values. 2. Format variables as replacements.

You need to know what your variable values are before conditions and replacements are defined. So, we'll start by relocating the "determine variable values" operation to just above the conditions definition.

Search for "<!-- Conditions -->" and move the code to determine variable values there:

Now, inside the conditions block, emit conditions as follows:

Finally, make sure your replacements are still being emitted:

That should do it.

Sample 2011.1 project with overrides:
Variables.zip

Variables Scoped per Page

Actually, what is happening is that your variable conditions code is working correctly. The problem is that ePublisher's variables implementation was built to be backwards compatible with certain WebWorks Publisher behaviors. Namely, the fact that once a variable is set, the value remains valid until it is changed.

ePublisher accomplishes this in the template:

This template is located in Shared\common\variables\variables.xsl.

So, what you need is a different "strategy" for selecting variable values. To do that, you can create a new variable selection template by cloning "Variables-Globals-Split" to something like "Variables-Per-Page-Only".

The guts would be a cut down version of the original "Variables-Globals-Split", something like:

Sample 2011.1 project with overrides:
Variables.zip

DevCenter/Projects/Variables - Conditional per Page (last edited 2011-05-31 15:32:45 by BenAllums)