01298: Page variable for Page directives

Summary: Page variable for Page directives
Created: 2012-10-02 18:11
Status: Closed - local customization provided
Category: Feature
From: simon
Priority: 5
Version: n/a
OS: n/a

Description: Provide a page variable (or page text variable) for each of the following page directives that indicates if they have been activated for a specific page


This will allow use in conditional markup to support moving the wiki header from the template to a wiki page. This should work with existing use of markup such as (:noaction:).

This would support recipe and skin writers to, say, replace the template head with a header page (e.g. Site.PageHeader)

This is impossible because page(text)variables are expanded near the very beginning of the markup processing, way before page directives are read. This way some people use them to conditionally set a page directive like (:if {*$:Stuff}:)(:noleft:)(:if:) and we usually don't wish to change PmWiki in a way that would break their wikis.

OTOH, it can be trivial for you to create a skin recipe which would rely on PageTextVariables like (:notitle:1:) to enable or disable sections. --Petko November 10, 2012, at 03:39 PM

You could also tell PmWiki to consider these directives as PageTextVariables, the same way as other PTVs, that is ignoring escaped sections or conditionals. For example, the above strings can become PTVs like this:

 1 {*$:noaction}
 2 {*$:notitle}
 3 {*$:noleft}
 4 {*$:noright}
 5 {*$:noheader}
 6 {*$:nofooter}
 7 {*$:nogroupheader}
 8 {*$:nogroupfooter}
(:if {*$:noleft}:)
No sidebar!
(:if !{*$:noaction}:)
Show actions
 1 noaction
 2 notitle
 3 noleft
 5 noheader
 6 nofooter
 7 nogroupheader
 8 nogroupfooter

No sidebar! Show actions

To achieve this, we have in a local config file this super line:

  $PageTextVarPatterns['(:directive:)'] = 

Then, you can use them in conditionals. However, notice that on this page we have escaped strings; the PTV function works (for all PTVs) on the whole text regardless of escaped or conditional markups. And this cannot be changed. Also note that PTVs are case sensitive; your directives must be all lowercase, (:NoTitle:) will not become a PTV. This cannot be changed either. --Petko November 10, 2012, at 03:39 PM

Or, more generally, perhaps one could add a $PageTextVarPattern that treats any PmWiki directive as a PTV. I tend to think it should be a recipe, though, and not part of the core. I'd need to see more justification about why it needs to be core.

Pm November 12, 2012, at 07:10 AM

I added the "local config file super line" to config.php and it worked well. One of the powers of PmWiki is its flexibility, and providing reflection of these page directives from wiki pages in the core allows more innovation. I recommend that this be added as a Core Candidate.

Simon June 16, 2019, at 02:05 AM


(:if {$Action} :)
  (:include Site/PageActions :)