17/12/2006. The minor core code mod required for this modified dropmenu to work has now been done for 0.9.5. See http://modxcms.com/forums/index.php/topic,2612.0.html05/12/2006. This modified DropMenu snippet requires a minor change to the core code. Originally the mod was done for 0.9.1, but I've posted the version for MODx-095rc3-rev2066 on page 3 and updated the related topic referenced below.Updated on 15/04/2006 to add new NOT join method (because it's difficult to write regular expressions that return everything not matching a pattern) and assign a css class to weblinks.Hi all.
I've modified the DropMenu snippet to support the following:
1. Show all items regardless of whether they've been flagged to appear in the menu or not.
2. Link to a weblink's URL rather than the weblink itself.
3. Filter docs via a regular expression on their keywords.
4. Filter docs via a regular expression on a given template variable.
5. Join the results using AND, XOR, OR, NOT.
6. Assign a css class to weblinks (so they can be styled to indicate they're external links).
The new config parameters are as follows:
&showAllInMenu - [ true | false ] If true prevents docs being filtered by their 'sitemenu' flags. i.e. all appropriate docs are output regardless of whether they've been flagged to appear in the menu or not. Defaults to false.
&useWeblink - [ true | false ] If true and the doc is of type 'reference', link to the doc's weblink (it's 'content' field) rather than to the doc itself. Defaults to false.
&keywordRegexp - [ string ] A regular expression to check against the keywords. This filters out all docs other than those with a matching keyword.
&tvRegexpField - [ string ] The name of a template variable on which to apply a regular expression. The regexp is specified using the &tvRegexpString parameter.
&tvRegexpString - [ string ] A regular expression to check against the given template variable. This filters out all docs other than those with a matching TV. The TV is specified using the &tvRegexpField parameter.
&joinMethod - [ "and" | "xor" | "or" | "not" ] A string that indicates whether to join the filter results using an AND (intersection), an XOR (difference) or an OR (union). If the NOT operation is used, it returns all documents except those that were matched. Defaults to OR (union).
&weblinkClass - [ string ] CSS class for a weblink's anchor. Defaults to "weblink".
I've used this new functionality on my site
http://mindspill.net to build pages of links based on the value of a "keywords" template variable. I've got several folders that store related links, like computing links or media links, then add more fine-grained categorisation by using the "keywords" TV.
My use of a "keywords" TV allows me to have admin defined keywords (via the built in keywords system) as well as user defined keywords (via the TV).
The changes to DropMenu could easily be used to create a section/category setup, where the sections are folders and categories are defined by the value of a template variable.
Note that allowing the use of Keywords and TVs with weblinks required some changes to core code, which I'll post a little later... Now posted..
http://modxcms.com/forums/index.php/topic,2612.0.htmlThe code can be optimised, so please let me know if you do so. Also, whilst I'm fairly sure the changes I made do not intrude on current functionality I've only tested it within the bounds of my setup.
Let me know whether you find these changes useful. Also, whether you think I should have made a new snippet rather than modify one that does a perfectly good job within it's scope. I'm not sure how the MODx and it's community prefer things to be done. Let me know.
Thanks.
Steph
P.S. Code in next post.