|
Cookbook /
EditMXSummary: Allow Markup Expressions to be used in the editing of a page
Version: 2008-05-04
Prerequisites:
Status: Alpha
Maintainer: Peter Bowers
Categories: Markup MarkupExpressions
Download: EditMX.phpΔ
Questions answered by this recipe
DescriptionAllow the return value of Markup Expressions to be inserted as text in a page. InstallationDownload EditMX.php and place it in your cookbook directory. If you plan on using this recipe for "macros" in your templates then use a conditional like this to actually include it (the array should contain a list of all your template pages):
if (!in_array($pagename, array('MyGroupA.Template', 'MyGroupB.Template')))
include_once('cookbook/EditMX.php');
or
$EditTemplatesFmt = '$Group.Template';
if (!preg_match('/.*Template$/',$pagename))
include_once('cookbook/EditMX.php');
(It is necessary not to have EditMX included on your actual template pages because then every time you edit your template to make a change you lose all your "macros".) NotesIf you want your MX to be replaced from a template when creating a new page from the template then surround the MX with If you want your MX to be replaced on save then instead of the usual It is advised to "debug" your MX using ExamplesExample: Put a date in a templatePlace this in the source of your template page:
If this page were created tomorrow instead of today it would be created on this date: {ROE(ftime fmt="%Y-%m-%d" tomorrow)}
Now whenever this template is used to create a new page you will have tomorrow's date in that spot. Example: Place text in your template dependent on the existence of another page:Place this in the source of your template:
{ROE(wikish if test -f GroupA.Page1; then; echo "Refer to [[GroupA.Page1]] for more details"; else; echo "Refer to [[Main.Page1]] for more details"; fi)}
Then if GroupA.Page1 exists you can refer to it but otherwise you can refer to another page. Example: Page List (requires powertools.php)While editing a page I decide I want a list of pages from the group Test to be inserted at a certain point in my text. I insert my MX so my page looks like this:
Below you have a list of all pages in the Test group
{ROS(pagelist group=Test wrap=inline fmt=#simple)}
And that's all, folks!
And when you go back in to edit the page you will see this: Below you have a list of all pages in the Test group * [[Test.Foo]] * [[Test.Foo2]] * [[Test.Foo99]] * [[Test.Foo99x]] * [[Test.IncludeMyURL]] * [[Test.NestedIf]] * [[Test.NewPTV]] * [[Test.TrailIndexPage]] And that's all, folks! Example: Inserting some repetitive text that varies slightly (requires WikiSh)I would like to insert a paragraph several times but in each paragraph I want a certain location to contain different values (ala mailmerge) While editing the page enter this text (all on one line - I've divided it here just for formatting purposes):
{ROS(wikish for name in John Sally Jack Sam Brittany Julie; do; echo "Hello, ${name}. I hope you're having a great day. By the way,
I think ${name} is just a beautiful name. TTFN!"; done)}
After saving, your source will look like this Hello, John. I hope you're having a great day. By the way, I think John is just a beautiful name. TTFN! Hello, Sally. I hope you're having a great day. By the way, I think Sally is just a beautiful name. TTFN! Hello, Jack. I hope you're having a great day. By the way, I think Jack is just a beautiful name. TTFN! Hello, Sam. I hope you're having a great day. By the way, I think Sam is just a beautiful name. TTFN! Hello, Brittany. I hope you're having a great day. By the way, I think Brittany is just a beautiful name. TTFN! Hello, Julie. I hope you're having a great day. By the way, I think Julie is just a beautiful name. TTFN! (OK, so it's a dumb example - you get the idea and at some point it may come in handy for repetitive text...) Example: Inserting Pages (requires WikiSh.php)You want to have the source of several different pages inserted (not included - you want to edit them or delete the other pages or etc) in the current page. Obviously you could go and open up each page individually and copy/paste it into place, but this is a whole lot faster and less error prone. While editing the target page you will enter this text:
(:linebreaks:)
{ROS(cat --file_prefix:"---PAGENAME---" Test.PageA Test.PageB Test.PageC)}
When viewing the page it will look very similar to an include, but when you go back in and edit the page you will see that the actual text was included (the optional --file_prefix:"PAGENAME" generated the separating lines): (:linebreaks:) ---Test.PageA--- I am the text from PageA ---Test.PageB--- I am the text from PageB ---Test.PageC--- I am the text from PageC Example: TextExtractExample unfinished Example: A quick calculator while editing (requires WikiSh although something similar could be done with MarkupExprPlus or MarkupExpressionsExtensions)This page while editing
The result of adding 1 and 2 and 3 and 4 and dividing all that by 2 is {ROS(set -v junk = "(1 + 2 + 3 + 4) / 2")}
Becomes this after saving The result of adding 1 and 2 and 3 and 4 and dividing all that by 2 is 5 Release Notes
See AlsoWikiSh provides an alternate method of creating a WikiTrail from a list of pages. It will place the markup in each of the target pages as well as creating the list itself. ContributorsHenrik came up with the idea of using this for Comments |