[pmwiki-users] Include specific lines of text on a page
Hans
design5 at softflow.co.uk
Sat Jan 19 06:02:35 CST 2008
Friday, January 18, 2008, 8:24:52 PM, wiki question wrote:
> Maybe -- Can you explain how page text variable work.
> A simplified example of what I am trying to accomplish:
> Page basically contains:
> TEST_NAME TEST_STATUS
> Test A Complete
> Test B Not Started
> Test C In Progress
> Test D Complete
> Test E In Progress
> ...
> ...
> ..
> I want to display, on a seperate page, only those tests that are completed and
> have it refresh when the main page is updated.
> So in the current state Test A and D will display
This is a tricky problem. I don't think page text variables are the
best answer, but I will explain it a bit, before offering a different
solution:
Page text variables (PTVs) can be defined in various ways, but the variable
name cannot contain spaces and has to start with a letter.
So your MainPage could contain this, which will automatically defines
PTVs:
TEST_NAME: TEST_STATUS
Test_A: Complete
Test_B: Not Started
Test_C: In Progress
Test_D: Complete
Test_E: In Progress
Each PTV can be referred to as {$:Var}, i.e. {$:Test_A}, which
displays its value, i.e. 'Complete'.
From a different page it can be referred to with
{PageName$:Var}, i.e {MainPage$:Test_A}
And importantly PTVs can be used in conditional markup.
So your page can contain this:
!!Completed Tests:
(:if {MainPage$:Test_A} 'Complete':)Test A
(:if {MainPage$:Test_B} 'Complete':)Test B
etc.
(:ifend:)
This may give you an idea how to work with PTVs.
It may even be good enough for your problem.
A different approach, I thought, would be to extract text rows from
a page which contain a certain string. Here is a definition of a markup
expression which does this. It should be added to config.php:
# {(textrows 'STRING' PAGENAME)} displays textrows from page PAGENAME which
# have STRING in them (as a substring). STRING is case sensitive.
# {(textrows 'STRING' PAGENAME#section)} displays textrows with STRING from
# section #section of PAGENAME.
# The current page cannot be a source for textrow extraction.
$MarkupExpr['textrows'] = 'ExtractTextRows($pagename, @$args[0], @$args[1])';
function ExtractTextRows($pagename, $str, $source) {
if ($str=='' || $source=='') return '';
$pn = MakePageName($pagename, $source);
if ($pn==$pagename) return '';
$page = RetrieveAuthPage($pn, 'read', true);
$text = $page['text'];
$section = TextSection($text, $source);
$textrows = explode("\n",$section);
$newrows = array();
foreach ($textrows as $row) {
if (strstr($row, $str))
$newrows[] = $row;
}
return implode("\n", $newrows);
}
So with this you could put into the page:
{(textrows Complete MainPage)}
and it will display:
Test A Complete
Test D Complete
Note it displays whole text rows, not just Test A, Test B.
It is a text extraction tool, and can be sourced from a whole page or
a page section.
I suppose it could be easily modified, for your case, to remove the
STRING from the textrows, by changing in the function this:
foreach ($textrows as $row) {
if (strstr($row, $str))
$newrows[] = $row;
}
with this:
foreach ($textrows as $row) {
if (strstr($row, $str)) {
$row = substr_replace($row, '', strpos($row, $str), strlen($str));
$newrows[] = $row;
}
}
~Hans
More information about the pmwiki-users
mailing list