(:Audience: authors, admins (intermediate) :) (:Summary:Listing pages by multiple criteria with templated output:) PmWiki comes with two directives for generating lists of pages -- [@(:pagelist:)@] and @@[=(:=]searchresults:)@@. Both directives are basically the same and each accepts the parameters documented below. The primary difference between the two is that searchresults generates the "Results of search for ..." and "### pages found out of ### searched" messages around the results. The [@(:searchbox:)@] directive generates a search form (input text box) to submit search queries. The markup generally accepts the same parameters as [@(:pagelist:)@], which makes it possible to restrict, order and format searchresults in the same ways that are described below for a [@(:pagelist:)@]. For more information about the [@(:searchbox:)@] directive, and the ways in which it differs from a [@(:pagelist:)@], skip to the section [[#searchbox|below]]. !! Basic syntax * [@(:pagelist:)@] ->without any arguments shows a bulleted list of all pages, as links, ordered alphabetically and in groups. * @@[=(:=]pagelist [[#pagelistgroup|group]]=''ab'' \ [[#pagelistname|name]]=''cd'' \ [[#pagelistfmt|fmt]]=''[[page list templates|template]]'' \ [[#pagelistlist|list]]=''ef'' \ [[#pagelistorder|order]]=''gh'' \ [[#pagelistcount|count]]=''123'' \ [[#pagelistlink|link]]=''ij'' \ [[#pagelisttrail|trail]]=''kl'' \ [[#pagelistwrap|wrap]]=''mn'' \ [[#pagelistpasswd|passwd]]=''op'' \ [[#pagelistif|if]]=''qr'' \ [[#pagetextvariables|$:''ptv'']]=''st'' \ [[#pagevariables|$''pv'']]=''uv'' \ [[#pagelistcache|cache]]=0 \ ''[[#pagelistarg|argument]]1'' -''[[#pagelistarg|argument]]2'' ''etc'' \ [[#includevariable|variable]]=''value'' \ [[#pagelistclass|class]]=''class'' \ [[#pagelistrequest|''request=1'']] \ [[#pagelistreq|''req=1'']] \ :)@@ ->shows a pagelist according to the parameters supplied. Parameters are optional. * @@[=(:=][[#searchbox|searchbox]] value=''abc'' size=''99'' target=''def'' label="label":)@@ * @@[=(:=][[#searchresults|searchresults]]:)@@ !! Parameters [[#pagelistarg]] Any argument supplied within [@(:pagelist:)@] that isn't in the form @@'key=value'@@ is treated as text that either must (or must not) exist in the page text. The minus sign (-) can be used to indicate things that should be excluded. Thus ->[@(:pagelist trail=PmWiki.DocumentationIndex list=normal apple -pie:)@] lists all "normal" pages listed in the [[Documentation Index ]] trail that contain the word "apple" but not "pie". !!![[#pagetextvariables]]With page text variables You can also use [[page text variables]] as a ''key'' to list pages according to the existence of a page text variable. Eg : ->[@(:pagelist $:pagetextvar=avalue:)@] lists pages having ''$:pagetextvar'' set to ''avalue''. [[<<]] Minus sign (-), wildcards (?*) and a comma separated list of values also works when specifying a selection based on pagetextvariables. Eg : ->[@(:pagelist $:apagetextvar=t*,-test:)@] lists pages having $:apagetextvar like 't*' but not 'test'. [[<<]] Examples: ||width=* class="tabtable" rules=rows ||PTV is set (is not empty): ||[@(:pagelist $:MyPageTextVariable=- :)@]|| ||PTV is empty or not set:[[<<]] (ie, is not set to one char followed by 0 or more chars) ||[@(:pagelist $:MyPageTextVariable=-?* :)@]|| ||PTV is not VALUE: ||[@(:pagelist $:MyPageTextVariable=-VALUE :)@]|| ||PTV is set and not YES: ||[@(:pagelist $:MyPageTextVariable=?*,-YES :)@]|| Be aware that if using [@(:pagelist $:MyPTV=$:YourPTV :)@] PTVs include PmWiki formatting, so you may not get the matches you expect. Currently the only way around this is to use wild cards, so if the formatting is embedded you may be out of luck. NOTE: Pagelist does not evaluate [[PmWiki/MarkupExpressions]] when working with PTVs. So if your [[page text variables]] is defined using a markup expression to set the value, pagelist will see the literal values of the text of your markup expression rather than the result of your expression. (e.g., the PTV definition [@(:foo:{(substr abcdef 2 4)}:)@] will be seen by pagelist as an open-curly-brace followed by an open-paren followed by s-u-b-s-t-r, etc. rather than being seen as b-c-d-e) Any processing of the markup expression in the output of your pagelist occurs in subsequent rules (after pagelist) within the context of the current page and thus these values cannot be used for sorting or selecting pages. ([[http://thread.gmane.org/gmane.comp.web.wiki.pmwiki.user/60968/focus=60970|source]]) !!![[#pagevariables]]With page variables (PV) Page variables can be used within pagelists in the same way as page text variables. See [[#pagetextvariables|Page Text Variables]] above for more details. Simply use $var instead of $:var. !!![[#pagelistgroup]] group= and [[#pagelistname]]name= The "[@group=@]" and "[@name=@]" parameters limit results to pages in a specific group or with a specific name: (:table class='tabtable' rules=rows:) (:cellnr:)All pages in the Pmwiki group: (:cell:)[@(:pagelist group=PmWiki :)@] (:cellnr:)All pages except those in the PmWiki or Site groups: (:cell:)[@(:pagelist group=-PmWiki,-Site :)@] (:cellnr:)All RecentChanges pages (:cell:)[@(:pagelist name=RecentChanges :)@] (:cellnr:)All pages except RecentChanges (:cell:)[@(:pagelist name=-RecentChanges :)@] (:tableend:) !!! Wildcards Name and group parameters can contain ''wildcard'' characters that display only pages matching a given pattern: * An asterisk (*) represents zero or more characters * A question mark (?) represents exactly one character Examples: (:table class='tabtable' rules=rows:) (:cell:)All pages in any group beginning with "PmWiki" (:cell:)[@(:pagelist group=PmWiki* :)@] (:cellnr:)All pages in any group beginning with "PmWiki", except for Chinese (:cell:)[@(:pagelist group=PmWiki*,-PmWikiZh :)@] (:cellnr:)All pages in the PmCal group with names starting with "2005": (:cell:)[@(:pagelist name=PmCal.2005* :)@] (:cellnr:)All Cookbooks with names beginning with a A and a B letter ->note the different separators used for the same result (:cell:)[@ (:pagelist group=Cookbook name=A*,B* :) (:pagelist group=Cookbook name="A* B*" :) (:pagelist group=Cookbook name=[AB]* :) (:pagelist group=Cookbook, name=[AB]* :)@] (:tableend:) If you want to use multiples conditions in name you need to use quotes or commas to delimit the string. For example -> [@key="one value,another value"@] !!![[#pagelisttrail]] trail= The "[@trail=@]" option obtains the list of pages to be displayed from a [[WikiTrail(s)]]: * Display pages in the documentation by modification time ->[@(:pagelist trail=PmWiki.DocumentationIndex order=-time:)@] * Display five most recently changed pages ->[@(:pagelist trail=RecentChanges count=5:)@] !!![[#pagelistlist]] list= The "[@list=@]" option allows a search to include or exclude pages according to predefined patterns set by the administrator. * "[@list=normal@]" is predefined, and which excludes things like AllRecentChanges, RecentChanges, GroupHeader, GroupFooter, GroupAttributes, and the like from being displayed in the list results. Note that list=normal also excludes the current page. * "[@list=all@]" over-rides a "default" list that may be set by the wiki's administrator to exclude groups such as PmWiki or Site from regular search results. * Wiki administrators can define custom lists via the $SearchPatterns array (see [[Cookbook:SearchResults]]). !!![[#pagelistfmt]] fmt= The "[@fmt=@]" option determines how the resulting list should be displayed. PmWiki [[Site/PageListTemplates|predefines]] several formats: * @@fmt=#bygroup@@ - Display pages within groups (default format) * @@fmt=#simple@@ - Display a simple ordered list of pages in the form Group.Name * @@fmt=#title@@ - Display a list of pages by page title. Use "[@order=title@]" to have them sorted by title (default is to order by page name). * @@fmt=#group@@ - Display a list of wikigroups (without listing the pages in the groups) * @@fmt=#include@@ - Display the contents of each page in the list (note, this could take a very long time for long lists!) These formats are defined by [[page list templates]], which can be customized. This format is not predefined by a page list template: * @@fmt=count@@ - Display the number of pages in the list (note the absence of the "#"). In a trail, @@fmt=count@@ counts existing and non-existing pages ; to limit count to existing pages, use : @@if="exists {=$FullName}" fmt=count@@ [-([[http://thread.gmane.org/gmane.comp.web.wiki.pmwiki.user/58621|mailing list]])-]. !!![[#pagelistlink]] link= The "[@link=@]" option implements "backlinks" -- i.e., it returns a list of pages with a link to the target. It's especially useful for [[categor(ies)]]y pages and finding related pages. * all pages with a link to PmWiki.DocumentationIndex ->[@(:pagelist link=PmWiki.DocumentationIndex:)@] * all pages with links to the current page ->[@(:pagelist link={$FullName}:)@] * all pages in the "Skins" category ->[@(:pagelist link=Category.Skins:)@] Note that the @@link=@@ parameter doesn't accept multiple or negative targets and wildcard lists. For these see Cookbook:PageListMultiTargets. Also, @@link=@@ will ignore the directives @@[=(:if...:), (:include...:), (:redirect...:), (:pagelist...:)=]@@, and page text variable directives, while searching for links in a page. That means links in included pages will not be found, and links inside non-displayed conditional markup will be found. See [[PageTextVariables]] for ways to hide a link on a page while still allowing @@link=@@ to find it. !!![[#pagelistcount]] count= The "[@count=@]" option provides the ability to * limit the pagelist to a specific number of pages * subsets of a list * return items from the end of a list, subsets of a list * display pages in reverse sequence (:table class=tabtable rules=rows:) (:cellnr:)A simple bullet list of ten most recently modified pages (:cell:) [@(:pagelist trail=Site.AllRecentChanges count=10 fmt=#simple:)@] (:cellnr:)Display the first ten pages of a list (:cell:) [@count=10 # display the first ten pages of list@] (:cellnr:)Negative numbers specify pages to be displayed from the end of the list: (:cell:) [@count=-10 # display last ten pages of list@] (:cellnr:)Ranges may be specified using '..', thus: (:cell:) [@count=1..10 # first ten pages of list count=5..10 # 5th through 10th pages of list@] (:cellnr:)Negative numbers in ranges count from the end of the list: (:cell:) [@count=-10..-5 # 10th from end, 9th from end, ..., 5th from end@] (:cellnr:)Omitting the start or end of the range uses the start or end of the list: (:cell:) [@count=10.. # skip first ten pages count=..10 # 1st through 10th page of list count=-10.. # last ten pages of list count=..-10 # all but the last nine pages@] (:cellnr:)Ranges can be reversed, indicating that the order of pages in the output should likewise be reversed: (:cell:) [@count=5..10 # 5th through 10th pages of list count=10..5 # same as 5..10 but in reverse sequence count=-1..1 # all pages in reverse sequence@] (:cellnr:)"Reverse sequence" here refers to the sequence ''after'' any sorting has taken place. Therefore the three directives to the right are equivalent: (:cell:) [@(:pagelist order=-name count=10:) (:pagelist order=-name count=1..10:) (:pagelist order=name count=-1..-10:) @] (:tableend:) !!![[#pagelistwrap]] wrap= The "[@wrap@]" option has the values, ''none'' and ''inline''. With "wrap=inline" and "wrap=none", the output from pagelist (markup or HTML) is directly embedded in a page's markup without any surrounding
class=...
tags. With "wrap=inline", any surrounding