We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33372
    • 1,611 Posts
    Hello -

    I’m sure that I can do this with MODx, but I’m not sure how to go about it. Rather than create my own hack to make this work I thought I’d consult the community first. Please forgive me if this turns out to be something that has been answered before.

    I am building a site for a professional association with multiple member organizations. So much of the site will be a directory of these members, which I plan to create as a folder of documents (one document per member) that are combined just like a newsListing page.

    OK so now the trickier part: I also want to be able to put each member into multiple categories (depending upon what type of services they offer, etc.) and create/sort the list dynamically depending upon what a user wants to see. So say they want to see only organizations that do graphic design, they could click on that category and see those members only. Later I may add other categories (geographical region, etc.), so ideally the system should be flexible.

    So basically I need to "tag" each member document with each category that they should appear in. I am imagining checkboxes in the document editor where you can just check all that apply for each member. Then I would just make a snippet that gets all members in the folder with X category checked (or X and Y if I decide to let users drill down).

    So my question is how to set up these check boxes (or something like that)? I’m new to MODx, but I’ve done several Etomite sites and with it you could use a mod called DocVars that would do this for you. Since this seems like something that’s been integrated into MODx with TVs, I bet I’m not the first person to set this up and someone can keep me from reinventing the wheel.

    Thanks in advance for your replies!
      "Things are not what they appear to be; nor are they otherwise." - Buddha

      "Well, gee, Buddha - that wasn't very helpful..." - ZAP

      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
      • 22303 MODX Staff
      • 10,725 Posts
      A multi-select list TV should do the trick. A single TV representing your categories can have a multi-select list as the TV options, which can then be presented in the manager document editor or via quickedit to select and assign the appropriate categories to the document.

      Check out the TV documentation at http://modxcms.com/template-variables.html and start there; I’ll bet others can help you with the details of configuring the TV instance.
        • 33372
        • 1,611 Posts
        Indeed that seems like exactly what I need. Thanks! Took all of 3 minutes to set up, too.

        Now is there a pre-existing snippet available with the code I need to list all documents in folder X with the selected options for a given template variable? The MODx API seems a lot more powerful than I’m used to using. No need to write mySQL queries if the API already exists, right?

        If there’s a snippet that does anything remotely similar please bring it to my attention.
          "Things are not what they appear to be; nor are they otherwise." - Buddha

          "Well, gee, Buddha - that wasn't very helpful..." - ZAP

          Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
          • 33372
          • 1,611 Posts
          Anyone?

          Here’s what I need to do: I need a snippet that returns the document ids of all docs with X template variable value (my template variable is a multi-select).

          How do I access the template variable values via the MODx API?
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn't very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 22303 MODX Staff
            • 10,725 Posts
            Here’s a sample snippet I wrote to generate a GeoRSS XML feed for the new Yahoo! Maps AJAX API from a directory of documents representing specific locations. Ended up using another approach, but this should help demonstrate a simple use of the $modx->getTemplateVarOutput() API function...

            <?php
            $xmlContent= '';
            if (isset ($startId)) {
                $rssItemContent= isset ($rssItemTpl) ? $modx->getChunk($rssItemTpl) : '';
                if (empty ($rssItemContent)) {
                    $rssItemContent= "  
                <item>
                    <title>[+georss.pagetitle+]</title>
                    <link><![CDATA[[+georss.link+]]]></link>
                    <description>[+georss.description+]</description>
                    <ymaps:Address>[+georss.tv.address+]</ymaps:Address>
                    <ymaps:CityState>[+georss.tv.city+], [+georss.tv.state+]</ymaps:CityState>
                    <ymaps:Zip>[+georss.tv.zip+]</ymaps:Zip>
                    <ymaps:Country>[+georss.tv.country+]</ymaps:Country>
                </item>
                ";
                }
            
                if ($children= $modx->getActiveChildren($startId)) {
                    foreach ($children as $child) {
                        $itemContent= '';
                        if ($childTVs= $modx->getTemplateVarOutput("*", $child['id'])) {
                            foreach ($childTVs as $name => $object) {
                                $child["tv.{$name}"]= "{$object}";
                            }
                        }
                        $child['link']= $modx->makeUrl($child['id']);
            
                        $itemContent= $rssItemContent;
                        foreach ($child as $key => $value) {
                            $itemContent= str_replace('[+georss.' . $key . '+]', $value, $itemContent);
                        }
                        $xmlContent .= $itemContent;
                    }
                }
            }
            return $xmlContent;
            ?>


            Hope that helps a little...
              • 33372
              • 1,611 Posts
              Thanks! That does help. You pointed me to the right API calls, which I hadn’t been able to find in the documentation on my own.
                "Things are not what they appear to be; nor are they otherwise." - Buddha

                "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                • 31396
                • 3 Posts
                Hi,

                I am new to modx Development. Please tell me how to create a city directory and Business directory in modx. Let me know if there is a addons available. Please help me to create a city directory.

                Thanks advance.