TitleMarkup

Summary: setting a page title with the first title markup, subsequent titles (from included pages etc.) are ignored
Version: 2008-01-27
Prerequisites: PmWiki 2
Status:
Maintainer:

Questions answered by this recipe

How can I set page titles so included pages will not override my titles?

Note: Recent PmWiki versions provide this feature, see $EnablePageTitlePriority. --Petko

Description

This is an alternative title markup definition setting the title with the first title directive.

Adding the following to config.php will define the title markup so that "the first title encountered wins", subsequent title directives (on included pages or otherwise) will be ignored. Any $ indicating some variable injection is also defused (while page variables and page text variables will continue to work inside the markup):

## (:title ...:) First title wins, any subsequent (:title ...:) is ignored.
Markup('title','directives',
  '/\\(:title\\s(.*?):\\)/ei',
  "SetTitleMarkup(\$pagename, PSS('$1')) ");
function SetTitleMarkup($pagename, $arg) {
   static $tset = 1;
   $arg = str_replace('$','$',htmlspecialchars($arg, ENT_NOQUOTES));
   if ($tset==1)
      PCache($pagename, $zz=array('title' => SetProperty($pagename, 'title', $arg )));
   $tset++;
}

Notes

Release Notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See Also

Contributors

Comments

This recipe was something I really needed.
But then it happened to me that I used code like that:

  (:title Just a Title Text:)
  Which title will win?
  (:markup:)
  (:include PageWithTitle:)
  (:markupend:)

resulting in having the title of the included PageWithTitle. Yes, (:markup:) always executes at the beginning and that's the 'First Winning Title'.

So I made another recipe SignalWhenMarkup that sets a counter to signal when we are in (:markup:) code, included it in my local/config.php and changed the above function to care about $SignalMarkupMarkup:

function SetTitleMarkup($pagename, $arg) {
   global $SignalMarkupMarkup;
   static $tset = 0;
   if (!$SignalMarkupMarkup) $tset++;
   if ($tset==1) {
       $arg = str_replace('$','$',htmlspecialchars($arg, ENT_NOQUOTES));
       PCache($pagename, $zz=array('title' => SetProperty($pagename, 'title', $arg )));
   }
}

Tontyna February 01, 2009, at 03:22 PM

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.