MadCap Flare Tricks: How to Show/Hide a Background Image via a Condition

My team has been confronted with a new challenge this week. We document several products in the same MadCap Flare project, some of them are publicly accessible and others are for internal use, and need to have an “Internal” background image.

The background image is defined in the “body” element of our css:

body {
 background-image: url("internal.png");
 background-color: #cccccc;
}

Since you cannot apply conditions to the body element of the css (at least Flare does not support it), we had two possibilities to make the background image inclusion/exclusion configurable:

  • A: duplicate the css and assign one or the other to the target (we didn’t really want to go for this option, since it implies that every single change in the styles have to be applied to two different files, which is time-consuming and error-prone…)
  • B: Find a way to show/hide the background image with a condition in the target.

After trying out different approaches, I found one that works and can be applied to solve this problem. You still use two css, but only have to maintain one:

How to Make Background Images Configurable via a Condition

  1. Create a new condition for showing/hiding the draft watermark  (e.g: “internal” in the condition set “status”).
  2. Create an empty css (e.g. internal.css) and add a body element with just the background image attribute:
body {
 background-image: url("internal.png");
}

3. Apply the internal watermark condition at the top of the new css as follows:

/*<meta conditions="status.internal" />*/

Note that you don’t need to make any changes to this css in the future. All the changes to the styles should be made in the original css.

    4. Remove the background image attribute from the original css.

5. Open the original css and link it to the draft.css (to inherit the style provided the draft condition is valid):

@import url('draft.css');

6. Enable or disable the draft condition in the output.

7. In the General tab of the target, select the original css as master stylesheet.

By doing this, you tell Flare to apply all the styles defined in the original css and show the  internal background image only if the internal condition in the target is enabled.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s