PTVReplace
Questions answered by this recipe
How can I change Page Text Variables easily using links or forms?
How can I toggle between Page Text Variable values?
Description
Download ptvreplace.phpΔ, copy to cookbook folder and install in local configuration file with:
include_once("$FarmD/cookbook/ptvreplace.php");
This script enables replacing of page text variable (PTV) values in PTVs of form
(:Name:Value:)
- hidden PTVs:Name: Value
- definition listName: Value
- open listing
Markup syntax for replace links:
(:ptvreplace name=PTVName val=VALUE:)
Use " " for strings with spaces, like val="Value String"
Optional parameters:
- label=Change: link text label, by default Value is shown as link text
- target=Group.TargetPage: for replacements on TargetPage
- redir=1: redirect to TargetPage after replacement.
By default no redirection to a TargetPage takes place.
The redirect default can be changed with
$PTVRedirect = 1;
By default PTV replacing is enabled for other pages.
To disable replacing for other pages set in local config file:
$EnablePTVReplaceTarget = 0;
The replacement action can be done with ptvreplace link markup, and also with Input forms, using action ptvreplace.
Examples
Creating a toggle link to toggle a PTV value
(:ToDo:0:) ToDo - {$:ToDo} (:if eq {$:ToDo} 1:)(:ptvreplace name=ToDo val=0 label=Cancel:) (:if eq {$:ToDo} 0:)(:ptvreplace name=ToDo val=1 label="To do":) (:if:)
Changing 2 PTVs with input radio buttons
Using input controls you can change any number of PTVs in one action. You can use radio button, text fields, select drop-down boxes etc.
(:State:1:) State - '''{$:State}''' (:Val:red:) Val - '''{$:Val}''' (:input form name=form1 "{$PageUrl}":)(:input hidden action ptvreplace:) (:input radio State 1 checked:) State 1 (:input radio State 2:) State 2 (:input radio State 3:) State 3 (:input radio Val "red" checked:) Val red (:input radio Val "green":) Val green (:input radio Val "blue":) Val blue (:input submit post Change:) (:input end:)
Dummy form:
Notes
When creating input controls to change several PTVs in one action, it is important that the PTVs are of the same format. Otherwise undesired replacements may occur.
Release Notes
- 2007-04-26: Improved regex patterns (thanks GNUZoo!)
- 2007-03-13a: Changed link markup to display value by default if no label is set.
- 2007-03-13: Fixed small bug in replacement code.
- 2007-03-12a: Added definition list and open listing PTV types.
- 2007-03-12: Initial release
Comments
Hello, is it possible to combine this with Fox? I would like to create a form with which to add some PageTextVariables and to replace some others. If I add (:input hidden action ptvreplace:) to the fox form, it changes the variables I want but doesn't add the new ones from the fox template.
Thank you. Nick 19.12.2007
Fox does ptv replacements without this recipe and without extra filter function. You need to set ptvtarget=TARGETPAGENAME (can be a list) in the (:fox ...:)
markup or an (:input hidden ..:)
markup. Then fox will replace any values on any ptv it finds on the target page for which it has an input field. HansB December 19, 2007, at 05:11 AM
See Also
- SetPageTextVariable Set a PageTextVariable in PHP
- Toolbox for the writeptv() function and MiscMX for the
{(writeptv ...)}
markup expression
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.