|
Cookbook /
IncludeSectionSummary: Include a section from the first available among a list of pages
Version: 20090228
Prerequisites:
Status:
Maintainer: Petko
DescriptionInclude a section from the first available among a list of pages. The PmWiki 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. InstallationPlace 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 (: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:) NotesRelease Notes
See AlsoContributorsCommentsThanx for this recipe. SDV($SaveAttrPatterns['/\\(:includesection\\s+(\\S.*?):\\)/i'], ' '); Tontyna February 28, 2009, at 10:05 AM Thanks, added. --Petko February 28, 2009, at 01:58 PM 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. |