[pmwiki-users] New template expression markup....

The Editor editor at fast.st
Tue May 1 10:11:18 CDT 2007


On 5/1/07, Hans <design5 at softflow.co.uk> wrote:
> Tuesday, May 1, 2007, 3:30:22 PM, The Editor wrote:
>
> > I just put together a solution for my needs, mentioned in the other
> > post--by using a markup expression.  Basically:
>
> > 1) Use ZAP/Fox to create a page long these lines:
>
> > [[#ID1]]
> > name: Caveman
> > time: Today
> > comment: Welcome to the new section template system...
>
> > [[#ID2]]
> > name: Coyote
> > time: Tomorrow
> > comment: Guess he's gonna get deprecated...
>
> > [[#ID3]]
> > name: Editor
> > time: Soon
> > comment: One of these days I'll do my own website done!
>
> > 2) Second, create a template as normal (with {$$field} syntax).
>
> > 3) On the page you want to show the display put this markup:
>
> > {(section datapage templatepage)}
>
> > The rest is automatic.  I'll be adding it to the ZAPtoolbox and
> > MarkupExpressionsExtension list shortly as I believe it will prove
> > very useful.
>
> How does it handle when people post text (posting a message in a forum for
> instance) in form of
>
> time: I don't know yet
> place: my place
> people: just some friends
>
> I mean this is a common way of writing.
> Would it not collide with the STV pattern recognition?


Very good question.  Indeed it would...  Here's the code if anyone
cares to suggest a solution:

$MarkupExpr['section'] = 'MkExpExtSection($args[0], $args[1])';
function MkExpExtSection($data, $template) {
  $template = ReadPage($template);
  $template = $template['text'];
  $data = ReadPage($data);
  $sections = explode("[[#ID", $data['text']);
  unset($sections[0]);
  foreach ($sections as $i => $section) {
    $sectionarray = '';
    $lines = explode("\n", $section);
    $id = substr($line[0], 0, strpos($line[0], "]]"));
    $sectionarray['id'] = $id;
    foreach ($lines as $line) {
      if (strpos($line, ": ") !== false) {
        $f = substr($line, 0, strpos($line, ": "));
        $v = substr($line, strpos($line, ": ") + 2);
        $sectionarray[$f] = $v;
        }
      }
    $out[$i] = preg_replace('/\\{\\$\\$(\\w+)\\}/e',
'ZAPfieldreplace("$1", $sectionarray)', $template);
    }
  return implode("", $out);
  }

One simple solution would be to require double colons or some other
variation in the data page...  Or some kind of leading symbol, or an =
sign.  Open to suggestions...

time:: I don't know yet
place:: my place
people:: just some friends

Cheers,
Dan



More information about the pmwiki-users mailing list