|
Cookbook /
MoreCustomPageVariablesQuestions answered by this recipe
DescriptionYou can add to a local customisation (config.php) those sample commands :
and then use e.g. Please contribute here with some interesting implementations that you have, may be useful for other users. Date related variablesHere is a set of date related variables I add to all my PmWiki's ## set up custom page variables
For pagelist ordering(from Cookbook.CustomPagelistSortOrderFunctions). Sorting by title, disregarding leading A/An/TheAssumes pages named or titled as in "A Title" or "The Title" and you wish to disregard the leading A/An/The.
$FmtPV['$TitleNoArticle'] =
'preg_replace("/^ *(?:The|An?) /i", "", (@$page["title"] ? $page["title"] : $AsSpacedFunction($name)), 1)';
(:pagelist ... order=$TitleNoArticle ...:) Sorting with last name firstAssumes pages named or titled as ZachAble, JohnSmith, AaronZimmerman and the desire is to have it sort in that order, by last name.
$FmtPV['$TitleLastFirst'] =
'preg_replace("/^(.*?)([A-Z][a-z0-9_]*)$/", "\\\\2, \\\\1", (@$page["title"] ? $page["title"] : $AsSpacedFunction($name)))';
(:pagelist ... order=$TitleLastFirst ...:) $ProfileLinksCount and $ProfileTargetsThis page variable is used in the Cookbook listings here on PmWiki.org, to count the number of profile links in a recipe or in a talk page. This number could be an indication for the popularity of the recipe.
$FmtPV['$ProfileLinksCount'] = 'ProfileLinksCount($page["targets"])';
function ProfileLinksCount($targets) {
$cnt = substr_count($targets, "Profiles.")-1; # without the maintainer
return $cnt>0? "+$cnt" : '';
}
Note that newer recipes usually have fewer comments than older ones, and this number does not generally depend on the Quality, the Stability, and the Ease of use of a recipe. New version (2009-09-01)
function ProfileTargets($targets) {
return implode(' ', str_replace("Profiles.","",
preg_grep('/Profiles\\./',explode(',',$targets))));
}
$FmtPV['$ProfileTargets'] = 'ProfileTargets($page["targets"])';
$MarkupExpr['unique_count'] = 'count(array_unique($args))';
Notes
Release Notes
CommentsYou can write all the FmtPV definitions using the php date function a bit simpler like $FmtPV['$CurrentYear'] = 'date("Y")';
Using the php date function you are restricted to dates in English. To make your dates international use the php strftime function, for instance # add page variable , formats today's date as yyyy-mm-dd
$FmtPV['$Today'] = 'strftime("%Y-%m-%d", time() )';
You can write a SpecialFunction function and call it like $FmtPV['$SpecialVar'] = 'SpecialFunction($pagename)';
Thank you Hans for the simplification tip - I changed it above. About the localized dates, one should probably first call something like setlocale("fr_FR.utf8");
As I've never had luck with these (really), eventually suggested See Also
Contributors
QuestionsHi, is there a way to make a part of page name a variable in local config file. Some like with
{(substr "PmWiki" 0 1)}
function. Thanks, Teukka Sure. Use something like this after any scripts and recipes that you include: # Get the group and page name $pagename = ResolvePageName($pagename); $name = PageVar($pagename, '$Name'); $my_special_config_variable = substr($name, 0, 1);If you wish to use such a value as a custom PageVariable (in wiki pages), use this instead: $FmtPV['$Substr01'] = 'substr($name, 0, 1)';and use in the page {*$Substr01}. The variables $name and $group will be replaced on runtime. This also works with PageLists, use {=$Substr01} inside a pagelist template. --Petko October 11, 2007, at 09:48 AM
Thank You so much. This was great help for me. I have a template with an image I want to modify. Specifically, in the template file I have <img src="{ $ CustomImage}">. I want to modify this variable in the wiki edit mode so that I can set a unique "splash" image for each page. Is there anything like: {SetVar CustomImage test.jpg} that I can include in the bottom of my wiki code. chris I think many don't understand wiki templates. Consider the following: <!--wiki:{$Group}-{$Name}.Logo {$Group}.Logo {$SiteGroup}.Logo-->
Inside of a page template this will look for Group-Name.Logo first (where Group is the Group and Name is the Name), then Group.Logo (for the current Group), then ultimately fall back to the Site.Logo file. These turn into includes of the page... so to have a custom Logo per page, just define Group-Name.Logo files for each page. I have a question. Is it possible to store a variable from a cookbook using FmtPV and call it in the wiki? It works perfectly when I store a variable in config.php, but it doesnt when I write it in a cookbook. I suppose I should be clearly specifying in which php cookbook the variable is stored. I wrote : in the selectquery.php cookbook and in a page using this cookbook, i tried to call it using Thanks for the support... Chris In your script, place |