Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

IncludeSection

Summary: Include a section from the first available among a list of pages
Version: 20090228
Prerequisites:
Status:
Maintainer: Petko
Categories: Includes, Markup
Users: +1 (View / Edit)

Description

Include a section from the first available among a list of pages.

The PmWiki (:include Page1 Page2 Page3 #from#to:) directive does not work as advertized. If Page1 exists, but does not contain a section #from#to, it returns nothing without checking the other pages.

I have a list of pages that "may" contain a specific section. I need to include this section if it exists in the first page, if not: from the second page and so on. This recipe adds a new markup that does exactly this:

   (:includesection #from#to Page1 Page2 Page3:) 
   (:includesection #section Page1 Page2 Page3:) 

Note that the section anchors are the first parameter, unlike with the (:include:) markup.

Installation

Place the following code in local/config.php :

Markup('includesection', '>if',
  '/\\(:includesection\\s+(\\S.*?):\\)/ei',
  "PRR(IncludeSection(\$pagename, PSS('$1')))");
$SaveAttrPatterns['/\\(:includesection\\s.*?:\\)/i'] = ' ';

function IncludeSection($pagename, $inclspec)
{
  $args = ParseArgs($inclspec);
  $anc = array_shift($args['']);
  if($anc>'' && $anc{0}!="#") return '';
  foreach($args[''] as $v)
  {
    $x = IncludeText($pagename, "$v$anc");
    if($x>'') return $x;
  }
}

To set additional parameters such as lines= or basepage=, use such a markup (note the quotes):

   (:includesection "#from#to lines=3 self=1" Page1 Page2 Page3:) 

To specify different section names with each page, use this (note the quotes) :

   (:includesection "" Page1#sec1 Page2#sec2 Page3#sec3:) 

Notes

Release Notes

  • 20090228 : added $SaveAttrPatterns skip definition (suggested by Tontyna)
  • 20090112a : added way to specify different section names with each page
  • 20090112 : first release

See Also

Contributors

Comments

See discussion at IncludeSection-Talk

User notes +1: 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.

Edit - History - Print - Recent Changes - Search
Page last modified on October 21, 2013, at 08:27 PM