[pmwiki-users] markup expression: what name & where?

sti at pooq.com sti at pooq.com
Tue Nov 13 06:31:34 CST 2007


Hans wrote:
> Yes, very good. Might it work by giving the markup expression another
> "wrapper", so it is not evaluated when the page is created, but will
> only be evaluated when the form post is processed, by the form
> processor "unwrapping" it and calling MarkupExpression() directly with
> the expression? I imagine this as part of the initial
> variable substitutions.

I'm using a modified version of fox.php that defines any template expression
looking like {$$(func...)} as being equivalent to {(func...)}.

That way I can have any of the standard or extended markup expressions
available when I'm writing templates, but I can also embed markup expressions
into the pages being built, as {(func...)} is passed through uninterpreted.

The actual code looks like:

    $pregarr = array
      //replace {$$name} fields with values
      ( '/\\{\\$\\$([A-Za-z][-_\\w]*)\\}/e'
          => "FoxField(\$pagename,\$fields, PSS('$1'))"
      //replace {$$name[num]} fields
      , '/\\{\\$\\$([A-Za-z][-_\\w]*)\\[\\s*([0-9]+)\\s*\\]\\}/e'
          => "FoxField(\$pagename,\$fields, PSS('$1')), PSS('$2')"
      //replace old {$$(date:...)} function
      , '/\\{\\$\\$\\(date[:\\s]+(.*?)\\)\\}/e'
          => "date(PSS('$1'))"
      //replace {$$(strftime:fmt)}
      , '/\\{\\$\\$\\(strftime[:\\s]+(.*?)\\)\\}/e'
          => "strftime(PSS('$1'))"
      //replace {$$(function args...)}
      , '/\\{\\$\\$(\\(\\w+\\b.*?\\))\\}/e'
          => "MarkupExpression(\$pagename, PSS('$1'))"
      );

      ...

    //loop until no more field replacements are possible.
    SDV($FoxMaxIterations,100);
    $count = 0;
    do
      { $more = false;

        foreach($pregarr as $pat => $rep)
          {
            $string = preg_replace($pat,$rep,$string,-1,$cnt);
            if( $cnt )
              {
                $more=true;
                continue 1; // restart the do-loop
              }
          }
      }

This also allows me to nest the expressions so that things like

{$$(toupper {$$(pagename {$$foo})})}

Will work.



More information about the pmwiki-users mailing list