Parmset

Summary: Provide access to the current requests in the URL as a page variable
Version: 20150803
Status: Beta
Maintainer: RandyB
License: GPL2+
Users: +1 (view / edit)
Discussion: Parmset-Talk?

Questions answered by this recipe

Q. How do I create a link to change a request parameter in the URL without affecting other request parameters?
Q. How do I pass specific information to another page via a URL link?

Description

A page variable that contains the request information from the URL

This recipe provides a way to build pages and menus in a whole new way: via URL requests. You can use the {$parmset} page variable to retain the current information in the URL, and then just add or override whatever information you want.

By using this recipe, you can pass limited information between pages, just as in a programming language you would pass information between functions using global variables.

Installation

  • Copy parmset.phpΔ to your cookbook directory.
  • Add to your configuration file a line such as:
    include_once("$FarmD/cookbook/parmset.php");

Usage

Here's a toy example:

1. Add a ParmA parameter to the URL, replacing whatever value it had before

[[{$FullName}{$parmset}?ParmA=1|Add ParmA=1]]

Add ParmA=1

2. Add a ParmB parameter to the URL, without changing ParmA

[[{$FullName}{$parmset}?ParmB=1|ParmB=1]]

ParmB=1

After clicking the above two links in sequence, the URL should now contain the requests: ?ParmA=1?ParmB=1

3. Change the value of ParmB from 1 to 2

[[{$FullName}{$parmset}?ParmB=2|Change ParmB from 1 to 2]]

Change ParmB from 1 to 2

After clicking all the above links in sequence, the URL should now contain the requests: ?ParmA=1?ParmB=2

4. Remove ParmA from the URL, leaving just ParmB

[[{$FullName}{$parmset}?ParmA=|Remove ParmA]]

Remove ParmA

After clicking all the above links in sequence, the URL should now simply contain the request: ?ParmB=2

Here's an example of creating a menu system using Parmset and the Request recipe:

(:if request color red:) %frame% (:ifend:) [[{$FullName}{$parmset}?color=red|Red]] 
(:if request color green:) %frame% (:ifend:) [[{$FullName}{$parmset}?color=green|Green]]
(:if request size small:) %frame% (:ifend:) [[{$FullName}{$parmset}?size=small|small]] 
(:if request size large:) %frame% (:ifend:) [[{$FullName}{$parmset}?size=large|large]] 

>>(:if request color:){$?color} (:if request size:) font-size={$?size} (:ifend:)<<
This text is displayed in the color and size you selected.
>><<

Notes

  • To remove a parameter from the URL, just give it an empty value: {$parmset}?myparm=
  • This tool is very useful when combined with Cookbook:Request
  • You can create menus that allow users to successively refine parameters, for example to specify the group, order, and fmt of a pagelist
  • Because parmset returns the current requests in the URL, adding or changing a request creates a URL with both the before and after values. The last request is the active one: that is, in a URL with ?A=Old?A=New the value of A is New. The URL will not keep growing each time the link is clicked, because {$parmset} only returns the active version of the request.

Change log / Release notes

  • 20150803 - first public release, ready to be tested.

See also

Contributors

Recipe written and maintained by RandyB.

Comments

See discussion at Parmset-Talk?

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