I want to use php to populate each page's title tag and I can't find a reference to it on here, although I know it has been mentioned before. I'm therefore writing this short tutorial, partly so I can find the topic if I need to in the future, and also of course for the benefit of everybody else.

For those who aren't aware, if you leave the Website and Page (i.e. both) "Description" and "Keywords" meta fields blank they are not added to the exported HTML pages. Therefore, filling them dynamically is easy using a placeholders, either site-wide or on a page by page basis.

The <title> tag, however, is added whether you want it or not, and you can't add php code because if you do, this:
Code:
<title><php require("title.php"); ?></title>
becomes this:
Code:
<title>&lt;php require(&quot;title.php&quot;); ?&gt;</title>
when transmogrified by your Xara program.

So what you need to do is remove the Xara-generated code starting <html> and ending </head> so that you can add your own section, including your dynamically generated <title></title> tag. To do this:


  1. Export your page, view source and copy everything at the top between <html> and </head> that was inserted by Xara (i.e. not any <head> code you may have added yourself)
  2. Create a placeholder object and give it the Name <html>(lower case)
  3. Go to the Placeholder tab, [HTML code (body)], insert start php and add the start of a multi-line comment (i.e. <?php /* )
  4. Click OK and Apply
  5. Go to the Page tab and click [HTML code (head)], insert the end of a multi-line comment (i.e. */ )

    If you were to click OK and Apply at this point, once uploaded to your server, your HTML page would have no <html> or<head> content (save what you may have added yourself). This is clearly unsatisfactory, so in the same Placeholder as 5) above:
  6. After the end of the php, paste the<html> section of the page you copied in 1. above, e.g.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Code:
 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta name="XAR Files" content="php_htm_files/xr_files.txt"/>
 <title>Dynamic PHP Title Tag</title>
 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"/>
 <meta name="Generator" content="Xara HTML filter v.4.1.2.673"/>
 <link rel="stylesheet" type="text/css" href="php_htm_files/xr_main.css"/>
 <link rel="stylesheet" type="text/css" href="php_htm_files/xr_text.css"/>
 <script type="text/javascript" src="php_htm_files/roe.js"></script>
7. Edit the <head> section, editing/adding your own code as required, e.g.
Code:
*/ ?>

<!-- start custom header -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title><?php require("title.php"); ?></title>
<meta name="keywords" content="<?php require("keywords.php"); ?>"/>
<meta name="description" content="<?php require("description.php"); ?>"/>
<meta name="Author" content="Billy the Fish"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="XAR Files" content="php_htm_files/xr_files.txt"/>
<link rel="stylesheet" type="text/css" href="php_htm_files/xr_main.css"/>
<link rel="stylesheet" type="text/css" href="php_htm_files/xr_text.css"/>
<script type="text/javascript" src="php_htm_files/roe.js"></script>

<!-- end custom header -->
8. Click OK and Apply
Writing this down methodically has helped me, although I know it's been mentioned elsewhere, but as usual the site search engine has thwarted me! Anyways, I hope it helps at least one person other than me