5

I want to include a header in a bunch of pages, like so:

header.html:

<html>
  <head>
    <title>My site</title>
  </head>

To enable a page-specific title, I'm trying to use an SSI variable that I set in each page:

page1.html:

<!--#set var="TITLE" value="first page" -->
<!--#include file="header.html" -->

Then I”m modifying header.html to use that variable:

<title>My site - <!--#echo var="TITLE" --></title>

This works fine but, of course, it has the unfortunate effect that, if TITLE is not set, the result is:

<title>My site - (none)</title>

So I'm trying a variety of attempts at conditionally echoing that variable depending on whether it's none or not (e.g., <!--#if expr="TITLE != \(none\)" --> ... <!--#endif-->) …but nothing seems to work.

Seems like this would be quite a common requirement. Does anyone have a reference to a working solution?

Zearin
  • 107
  • 3
Bobby Jack
  • 318
  • 1
  • 5
  • 23

3 Answers3

5

For Apache 2.4 the expressions have changed:

<!--#if expr="-z v('CONTENT_LANGUAGE')"-->
<!--#set var="CONTENT_LANGUAGE" value="en"-->
<!--#endif-->
jwigley
  • 51
  • 1
  • 2
1

I've used this successfully:

<!--#if expr="! $CONTENT_LANGUAGE" -->
<!--#set var="CONTENT_LANGUAGE" value="en" -->
<!--#endif -->
Benxamin
  • 111
  • 3
0

OK, solved it myself. For others' reference:

<!--#if expr="${TITLE}!=''" -->

is the correct syntax to use. It makes sense that you don't have to check for "(none)" since the undefined text value can be configured; I just didn't realised that occurred after checking the value, not before.

Bobby Jack
  • 318
  • 1
  • 5
  • 23