01554: Configure default PTV values from a wiki page

Summary: Configure default PTV values from a wiki page
Created: 2026-05-15 19:23
Status: Closed, added for 2.6.0
Category: Feature
From: Petko
Assigned:
Priority: 1
Version: 2.5.9
OS:

Description: Moved from PageTextVariables-Talk

Configure default PTV values from a wiki page

Can we add some way to do this in the pseudo markup for pagetextvariable definitions? I call it pseudo markup because it is not as easily customizable as in the normal markup queue:

  _begin      start of translation
  {$var}      Page Text Variables happen here.
  fulltext    translations to be performed on the full text            
  split       conversion of the full markup text into lines to be processed
  directives  directive processing
  inline      inline markups
  links       conversion of links, url-links, and WikiWords     
  block       block markups
  style       style handling       
  _end        end of translation

How about something like (:name:value|defaultvalue:) Is there any reason this is not a good idea?

--gnuzoo

There is at least one reason what you wrote is a bad idea. If you can write (:name:value|defaultvalue:) in the page, you can instead write (:name:value:) or (:name:defaultvalue:) in the same page. I suspect you did not mean what you wrote but something entirely different. For new core feature requests, please open a PITS entry so we can see if there is interest in the community. Obviously, nothing prevents you from writing a recipe that preempts the {$var} markup rule and replaces core functions that handle it. --Petko


DOH!😂 Thinking too hard. 😂

This would be better. Use keyword 'default' or 'defaultunset' or 'defaultempty' in front
of a PTV default declaration separated from a potential PTV name by a space.

    # for unset or empty
    (:default name:value:) 

    # for unset
    (:defaultunset name:value:)

    # for empty
    (:defaultempty name:value:)

Instead of putting into the config.php file:

    $DefaultUnsetPageTextVars['bordercolor'] = $DefaultEmptyPageTextVars['bordercolor'] = 'red';

You could put:

    (:default bordercolor:red:)

Can we add this to pagetextvariable processing?
--gnuzoo

Think harder. Think why would someone want to write (:default bordercolor:red:) instead of directly (:bordercolor:red:). --Petko

You think harder. 😀

Because (:default bordercolor:red:) is not a PTV definition. It is a default value declaration.
(:bordercolor:red:) is a PTV definition.

A default declaration is easier to do inside the page code than having to edit the config.php file.
A default value declaration can directly be translated to:

    $DefaultUnsetPageTextVars['bordercolor'] = $DefaultEmptyPageTextVars['bordercolor'] = 'red';

--gnuzoo

Why would someone want to write a "default value declaration" in the page rather than the actual "value declaration" which is shorter, in the same page? The actual value declaration is even easier to write in the page than the default value declaration. --Petko

Because it can be used in an included page. When sommeone includes that page it has defaults.
The page that is doing the include can set their own values for particular PTVs that may not match
the defaults. They would not need to be passed in as name=value in the include statement.
The page doing the including can override the defaults by just setting a PTV.
AFAIK include arguments do not have defaults. PTVs do if you enter them into config.php.
I dont want to have to put them into the include statement evertime.

It makes PTVs more flexible too.

    $DefaultUnsetPageTextVars['bordercolor'] = $DefaultEmptyPageTextVars['bordercolor'] = 'red';

"default value declaration" moves that from config.php to the page. Much simpler to use.

--gnuzoo

For included pages you just need to define the variable in the including page, and write in the included template page {*$:borderwidth}, note the asterisk. This way the variable from the outer page is used. From another page, defining a different value and including the same template will have that value. --Petko

I think this may be more practical not as a definition/declaration but as an extracted value. Something like this: {$:borderwidth|1px} where it could return 1px if it is empty or undefined. The default value could only be single line, without internal braces. --Petko

I think you are missing the point.

Why does this exist:

    $DefaultUnsetPageTextVars['bordercolor'] = $DefaultEmptyPageTextVars['bordercolor'] = 'red';

Without that there is no default value for pagetext variables! I want to do that within a page.

--gnuzoo

You can set the actual value within the page. I suggested implementing {$:VarName|DEFAULT} but you claim I'm missing the point. Obviously there is a communication or understanding problem. Why don't you prototype the feature as a recipe/demo code/core diff as a proof of concept and we'll see what you really want and how it will work. --Petko

Perhaps I missed something, but I cannot make it more clear. Please contemplate this:

  $DefaultUnsetPageTextVars['bordercolor'] = $DefaultEmptyPageTextVars['bordercolor'] = 'red';

I will cease this discussion. Thanks for trying.
--gnuzoo

As I offered, I have now added for 2.6.0 {*$:SomeVariable|default value if empty or unset}. I am closing this entry. If you insist on a directive in a wiki page, specifically modifying the PHP variables $DefaultUnsetPageTextVars and $DefaultEmptyPageTextVars, I'll leave that for you or someone you hire to write and support in a recipe. --Petko