Cambios Recientes - Buscar:

Mientras no se diga lo contrario:
Creative Commons License

MarkupVariables

authors (intermediate)

This page describes the "variables" that are available in the markup through the construction {$<variable>}. For example, putting "{$Group}" in the markup of this page renders as "PmWiki".

Note: These variables do not necessarily exist in the PHP code, i.e. you cannot assume that using $group in local/config.php will produce the correct result. Instead, check the list of internal Variables first, you may find a match.

Here are the variables that are available through markup:

{$Group} - page's group name, as in "PmWiki"
{$Groupspaced} - spaced group name, as in "Pm Wiki"
{$DefaultGroup} - default group name, as in "Main"
{$SiteGroup} - default group name for e.g. RecentChanges, as in "Site"
{$Name} - page name, as in "MarkupVariables"
{$Namespaced} - spaced page name, as in "Markup Variables"
{$DefaultName} - name of default page, as in "`Inicio"
{$FullName} - page's full name, as in "PmWiki.MarkupVariables"
{$Title} - page title (may differ from Name), as in "MarkupVariables"
{$Titlespaced} - title/spaced page name, as in "Markup Variables"
{$UrlPage} - requested URL (valid only on the PageNotFound page)

{$LastModified} - date page was edited, as in "01 septiembre 2005 a las 05h18"
{$LastModifiedBy} - page's last editor, as in "Pm"
{$LastModifiedHost} - IP of page's last editor, as in "24.1.26.255"

{$Author} - the name of the person currently interacting with the site, as in ""
{$AuthId} - current authenticated id, as in ""

{$Version} - PmWiki version, as in "pmwiki-2.0.13"

administrators (intermediate)

Defining additional markup variables

You can define additional markup variables by adding something like the following to your configuration script (e.g. local/config.php):

 
	Markup('{$local-variables}', '>{$fmt}',
	  '/{\\$(Var1|Var2|Var3)}/e',
	  "\$GLOBALS['$1']");
	$GLOBALS['Var1'] = "Variable 1";
	$GLOBALS['Var2'] = "Variable 2";
	$GLOBALS['Var3'] = "Variable 3";

This method of adding the markup variables will also make them known to the function FmtPageName which may or may not be desirable. If you don't want that, then define the extra markup variables directly, like this:

	Markup('{$Var1}', '>{$fmt}', '/\\{\\$Var1\\}/', 'Variable 1');
	Markup('{$Var2}', '>{$fmt}', '/\\{\\$Var2\\}/', 'Variable 2');
	Markup('{$Var3}', '>{$fmt}', '/\\{\\$Var3\\}/', 'Variable 3');

Example 1

Let's say you want {$mygroup} to render as the name of the current group using only lower case letters. Here's how you could do it using the first approach described above:

 
	Markup('{$local-variables}', '>{$fmt}',
	  '/{\\$(Var1|Var2|mygroup)}/e',
	  "\$GLOBALS['$1']");
	$GLOBALS['Var1'] = "Variable 1";
	$GLOBALS['Var2'] = "Variable 2";
	$GLOBALS['mygroup'] = lower(FmtPageName('$Group', $pagename));

Using the second approach, you need to add something like this to your configuration script:

 
	Markup('{$mygroup}', '>{$fmt}',
	      '/\\{\\$mygroup\\}/', 
	      lower(FmtPageName('$Group', $pagename)));

	Markup('{$Var1}', '>{$fmt}', '/\\{\\$Var1\\}/', 'Variable 1');

	Markup('{$Var2}', '>{$fmt}', '/\\{\\$Var2\\}/', 'Variable 2');

Example 2

Here is an example of a situation where you can't really define a variable as described earlier. Let's say you want each instance of {$tic-toc} to be replaced with the current time in system ticks when that part of the page is output. The difference here is that a function needs to be invoked (to get the current time) for each of the occurences. In order to do this, just use the function Markup() as usual. Here's how it could be done:

 
	Markup('{$tic-toc}', '>{$var}',
	       '/\\{\\$tic-toc\\}/e',
	       "array_sum(explode(' ',microtime()))");

Links

Also see these pages:

<< Conditional markup | DocumentationIndex | Markup master index >>

ourproject.org Logo
Editar - Historia - Imprimir - Cambios Recientes - Buscar
Última modificación de la página el 01 septiembre 2005 a las 05h18