Variables

Summary: Allows to set variables in Wiki text to be used in the text and/or if markups
Version: 1.0
Prerequisites: PmWiki 2.1.5
Status: Stable
Maintainer: Americo Albuquerque
Categories: Obsolete

Questions answered by this recipe

Is there a markup to define a variable in a page, that can be used lateron?
(:set Name Tom:)
(:if equal $Name Tom:) or something like that .... ??

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.

Description

This recipe allows you to set variables that can be used later. Those variables are used using the {$var} syntax. This variables can also be used in (:if:) markups as condition test. You can also set variables inside (:if:) markups to be used in the same manner.

Notes

There are some problems inherent to the way PmWiki works that you have to take in consideration when using variables. The variable value used in (:if:) markups is the value of the last variable set with that name, even if it is define inside another (:if:) markup that happens to be false. Before the (:if:) markup is checked, all variables are set no matter where they are defined. Their final value is set after the (:if:) markup is checked and, due to that, the variable value can be different than the used in the next (:if:) markup.

Release Notes

There are some changes that need to be done to the main PmWiki php file for this recipe to work. Currentely, PmWiki doesn't allow to run 2 markups using the same regexp. This recipe needs that funtionality, so, for it to work you have to make this changes in pmwiki.php (on your main pmwiki install dir)

  In BuildMarkupRules change

  $MarkupRules[str_replace('\\L',$LinkPattern,$m['pat']] = $m['rep'];

  to

  $MarkupRules[] = array('pat'=>str_replace('\\L',$LinkPattern,$m['pat']), 'rep'=>$m['rep']);

  and in MarkupToHTML change

    foreach($markrules as $p=>$r) {

  to

    foreach($markrules as $preg) {
      $p = $preg['pat'];
      $r = $preg['rep']; 

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

Comments

  • Download and put variables.phpΔ in the cookbook folder.
  • Add include_once('$FarmD/cookbook/variables.php'); in your local/config.php file;

See Also

Contributors

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