Showing source for Property Lists
ProWiki
|
RecentChanges
|
Preferences
<b>Previous:</b> [[Page Queries]] The second major type of query is the Property List. Whereas a page query says, "for all pages that have this property", a property list says, "apply the following pattern for all properties of this type on this page". <h3>Property List Syntax</h3> All property lists look more or less like this: {*<i>query</i> : <i>pattern</i>*} Looks a lot like the Page Query, right? The only difference is the asterisk substituted for the question mark of a page query. But the meaning is completely different. Whereas a page query returns all of the pages that match the pattern, the property list returns all of the properties that match the pattern on a single page. <h3>Local Property Lists</h3> The simplest kind of property list is one that operates just on the current page. For example, let's give this page several ExampleItem properties: {{ExampleItem=A big black book}} {{ExampleItem=Deck of cards}} {{ExampleItem=Some pocket lint}} We can now add a query that goes through all of these properties and lists them: {*ExampleItem : <b>%%ExampleItem%%</b><br>*} That would get displayed like this: {*ExampleItem : <b>%%ExampleItem%%</b><br>*} That is, it's simply a list of values of that property. That isn't very interesting, is it? But we can make it a heck of a lot more interesting if those items are references to pages themselves, with their *own* properties. Say that each ExampleItem is actually the name of a page, and that each of those pages has an ItemName and ItemDescription property. Now we can do this: {*ExampleItem : <b>%%ExampleItem.ItemName%%</b> (<i>%%ExampleItem.PAGENAME%%</i>) -- %%ExampleItem.ItemDescription%%<br>*} That is, "For each ExampleItem on this page, take the value as a page name, and show the ItemName, PAGENAME and ItemDescription properties on *that* page". That shows up like this: {*ExampleItem : <b>%%ExampleItem.ItemName%%</b> (<i>%%ExampleItem.PAGENAME%%</i>) -- %%ExampleItem.ItemDescription%%<br>*} Neat, huh? I left the Pocket Lint undefined, so that you can see what happens if you use this syntax to refer to a page that isn't there. <h3>Property Matches</h3> You can also do queries aimed at single values rather than multiple ones. If you substitute a "+" for the "*" in the query, it will only fetch one value. The particular power of this alternative is that it will walk up the inheritance tree: if the property is defined by an ancestor of this page, the value will be taken from that ancestor. This can be useful if you want a default value. This variant is also useful as essentially an "if" statement. For example, this line: {+ExampleItem : <h4>ExampleItems</h4>+} renders like this: {+ExampleItem : <h4>ExampleItems</h4>+} because there are ExampleItems on this page. But if there's weren't any, the line would be omitted entirely. This is often useful for headers to lists -- you put in a property match for the header, then the actual query to list out the values. That way, the header only shows up if there *are* values of that property. <b>Next:</b> [[Display Templates]]