• [snippet] DropMenu. Modified for weblinks and regexp on keywords/TV.#

  • modx@mindspill.net Reply #1, 6 years, 3 months ago

    Reply
    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.html
    05/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.html

    The 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.


  • modx@mindspill.net Reply #2, 6 years, 3 months ago

    Reply
    Update 11/07/2006: Added latest version which includes parameters to set the message that displays when there are no menu items.

    Code attached below.

    Steph


  • rthrash Reply #3, 6 years, 3 months ago

    Reply
    Hi steph, this is really cool and thanks for sharing. You can compress the files into a .zip archive and attach them to posts.

    Personally, I think it's a great addition to DropMenu, which needs a thorough going-over again anyway... several other bugs and requests on our trakcer for the next rev anyway.

    Speaking of which, can you please note this thread/request on our bugtracker as a feature request for a future version. We might need two That's how we make sure things on the forum don't slip under the radar.

    You'll probably want to make two requests: one for the dropmenu snippet and one for the core code changes (which we'd love to see, too):
    Note that allowing the use of Keywords and TVs with weblinks required some changes to core code, which I'll post a little later.


  • modx@mindspill.net Reply #4, 6 years, 3 months ago

    Reply
    I've added the feature request to the bug tracker.

    http://modxcms.com/bugs/task/236

    I'll be back to post info about the core modifications, which are very basic btw.

    Steph


  • davidm Reply #5, 6 years, 3 months ago

    Reply
    Waow very nice additions to the DropMenu, I see several possible use for this in my next projects Keywords searching will probably make a LOT of people happy ! Same for regular expressions and join querry...

    I am downloading it and waiting for the code changes...


  • modx@mindspill.net Reply #6, 6 years, 3 months ago

    Reply
    I've updated my first 2 posts because I noticed some of the documentation was slightly incorrect.

    Steph


  • modx@mindspill.net Reply #7, 6 years, 3 months ago

    Reply
    Is there any way to update tasks on the bug tracker?

    Steph


  • rthrash Reply #8, 6 years, 3 months ago

    Reply
    I think just post a comment and that'll function as the same thing.


  • modx@mindspill.net Reply #9, 6 years, 3 months ago

    Reply
    I've added a new post with the changes I made to /manager/actions/dynamic/mutate_content.dynamic.action.php that allowed weblinks to have META Keywords and template variables.

    http://modxcms.com/forums/index.php/topic,2612.0.html
    Steph


  • jwtyler Reply #10, 6 years, 2 months ago

    Reply
    Installed this snippet and updated core I get this parse error... any ideas? I really like the show menu toggle.

    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « Execution of a query to the database failed - Unknown column 'sc.here' in 'order clause' »
    SQL: SELECT DISTINCT sc.id,sc.pagetitle,sc.description,sc.isfolder,sc.parent,sc.alias,sc.longtitle,sc.menutitle,sc.hidemenu,sc.introtext,sc.content_dispo,sc.contentType,sc.type,sc.template FROM `modx`.modx_site_content sc LEFT JOIN `modx`.modx_document_groups dg on dg.document = sc.id WHERE sc.parent = '0' AND sc.published=1 AND sc.deleted=0 AND (sc.privateweb=0) ORDER BY sc.here DESC;
    [Copy SQL to ClipBoard]

    Parser timing
    MySQL: 0.0797 s s (41 Requests)
    PHP: 0.1814 s s
    Total: 0.2611 s s