AddToggle
$EnableGUIButtons, Cookbook:ToggleQuestions answered by this recipe
Q. What's an easy way to create a toggle link if I don't know how toggle link markup works?
Q. How can I reduce the page source clutter created by toggle link markup?
Q. What is an easy way to keep in sync the show and hide versions of a toggle link's text?
Q. How do I put a toggle within another toggle?
Q. What's an easy way to create a list of questions with each answer hidden until clicked?
Like most toggle recipes, this recipe answers:
Q. How do I hide a section of a page until the user wants to see it?
Q. How do I make available info such as help and options without visually cluttering the page for the end reader?
Description
A GUIEdit button to convert selected text to a toggle link
The Cookbook:Toggle recipe allows markup to create a toggle link that shows or hides a div section. AddToggle provides a simple way for editors to convert selected text into a toggle's link text.
Installation
- Make sure the Cookbook:Toggle recipe is working on your site, and that you have set
in your configuration file (you will see guiedit buttons at the top of your edit form)$EnableGUIButtons= 1; - Copy addtoggle.phpΔ to your cookbook directory. (Note: the file should not end immediately after the final semi-colon - append a blank line if necessary.)
- Copy the button picture fileΔ to your pmwiki/pub/guiedit directory.
- Add to your configuration file lines such as:
# Define toggle icons for {$Show} and {$Hide} $FmtPV['$Show'] = "'▹'"; # triangle pointing down $FmtPV['$Hide'] = "'▿'"; # triangle pointing right include_once("$FarmD/cookbook/addtoggle.php");
Configuration
- You can change the characters assigned to the page variables $Show and $Hide to whatever you want, or delete those lines if you don't want an icon to appear in front of your link text.
Usage
Select in your markup the text that you want to be your link. For example:
My link text
Then click the guiedit button:
. The selected text will be transformed in the page's source into:
{(toggle 5615 "My link text")}
Hidden
(:div5615end:)
The page will show:
when the contents are hidden, and
▿ My link text Hidden
when the contents are showing.
Notes
- If nothing is selected, the button adds sample markup wherever the cursor is.
- Replace the "Hidden" text with whatever you want to show or hide.
- You can use the page variables
{$Show}and{$Hide}in other toggle directives as well, for a consistent look. - You can repeat the process inside the hidden area, to put toggles within toggles.
- Wikistyles should work, e.g.
%rfloat% {(toggle 5615 "Help")}puts a Help link on the right
How this recipe works
Since Toggle requires that each div on a page be unique, AddToggle generates a random number for the toggle. This allows multiple toggles to co-exist on the page. To simplify the markup (and to facilitate future updates), the AddToggle recipe converts the selected text into a markup expression, which in turn will bring into the page the required markup upon page rendering. It's as if you had put in your page source:
(:toggle id=toggle5615 hide nojs=2 show="{$Show} My link text" hide="{$Hide} My link text":)
(:div5615 id=toggle5615 :)
Hidden
(:div5615end:)
Change log / Release notes
- 20150723 - first public release, ready to be tested.
See also
- AddToggle Add a GUIEdit button to convert selected text to a toggle link
- FAQToggleList Adding toggle buttons to a definition list
- Request Extends conditional markup to test parameters in the URL, to allow pages to pass parameters via their URL links
- ShowHide Adds toggle buttons and links to show/hide sections and objects. Superseded by Toggle.
- Toggle Adds links or buttons for toggling (hiding/showing) elements on a page
- ToggleEdit easier addition of toggle-markup.
- ToggleHide Add links to toggle display of html block elements
- ToggleLink redirect to Cookbook:ShowHide for SiteAnalyzer click through link
- ToggleNext Unobtrusive WikiStyle-based toggle-next element; core feature since pmwiki-2.2.124.
- Toggler add text/code folding, from image or text (show or hide page content)
- UnToggle An unobtrusive show/hide toggle switch.
Contributors
Recipe written and maintained by RandyB.
Comments
See discussion at AddToggle-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.