We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20864
    • 4 Posts
    Dear modxcms experts,
    I am designing a site where I want the homepage to be built up with the introtext (or other tvar) of other 4 documents. I was thinking of using number TVars where the admin can put the document ids of the referenced contents. Is there a "prettier" way of pointing to other documents without having to insert the id by hand (maybe using the widget where the parent document can be selected) ?

    Thanks

    Tristan
      • 25663 MODX Staff
      • 12,272 Posts
      Are the options coming from just a few potential options? And by "just a few" I mean 10-15 or so (or less)?
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 20864
        • 4 Posts
        Unfortunately not, the list could be very large. Think of it as "higlights" of inner news articles chosen from different sections of the site.
        Ideally modxcms should provide a TVar type with a document selector.
          • 25663 MODX Staff
          • 12,272 Posts
          Why not create a TV for the documents that tells you to push those items to the home page, then on the home page use Ditto to display only those documents with that flag set?
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 20864
            • 4 Posts
            Yes, I’ve thought about that. But then I’d have to go and remove the flag from the older contents, and hunting them down could be tricky, whereas with my solution I would handle them centrally.
            Where do I file for feature requests ? wink
              • 25663 MODX Staff
              • 12,272 Posts
              In the bugtracker as a Feature Request. http://modxcms.com/bugs/
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 14412
                • 74 Posts
                I’m working on a site whose homepage also needs to display

                Quote from: NadirX at Apr 28, 2007, 07:47 AM

                higlights" of inner news articles chosen from different sections of the site.

                I have 9 sections on my site. Each section has a subfolder called "News" that contains all of those section’s news articles. In my homepage I want to display news from all sections, sorted by date.

                I’ll describe my solution to achieve this - maybe it can lead you in the right direction to get what you need.

                First, I applied the same template to each of the section’s root page - let’s call this the "Section" template.
                For this template, I created a number TV that just stores the News subfolder’s ID for each section - let’s call this "newsFolderID".

                Then, I created a small snippet - "getTV" - to generate a list of all the News folders on my site:

                <?php
                //Get a list of TV values, given a container and document's template
                	//Container Document, defaults to site root if none given
                    $container = isset($container) ? $container : 0;
                    //Section template to search for
                    $template = isset($template) ? $template : '';
                    //TV to search for
                    $TVname = isset($TVname) ? $TVname : '';
                    //Fetch the Template's ID from the database
                    $table_site_templates= $modx->getFullTableName('site_templates');
                    $tplId=$modx->db->getValue($modx->db->select("id", $table_site_templates, "templatename='$template'"));
                    //Fetch Children documents and get the TV's value on them
                    $res=$modx->getChildIds($container);
                    $result = '';
                    foreach ($res as $key=>$value){
                        $doc=$modx->getDocument($key);
                        if($doc['template']==$tplId){
                            if ($result != '') $result .= ',';
                            $TVvalue = $modx->getTemplateVar($TVname, '', $doc['id'], 1);
                            $result .= $TVvalue['value'];
                        }
                    }
                    return $result;
                ?>


                Finally, to list the news articles on the home page, i just called Ditto like this:

                [!Ditto?parents=`[[getTV?template=`Section` &TVname=`NewsFolderID`]]` &depth=`1` &display=`all` &limit=`10`!]

                I’m aware this is not quite what you’re looking for because you still need to fill in the news folder’s ID on each section’s root page, but at least you don’t have to mark each article with a flag. If you don’t want to sort the articles by date, you can change Ditto’s sort options to use different criteria (menuindex comes to mind...)

                Hope this helps!

                Regards, JP
                  Got Music? Try XSPFjukebox - Skinnable MODx Media Player
                  • 18397
                  • 3,250 Posts
                  Maybe something along the lines of things discussed in this thread: http://modxcms.com/forums/index.php/topic,14316.msg93501.html#msg93501