We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14104
    • 4 Posts
    Hi

    I’ve been using MODx for about 3 days and am building a site to learn it. I am therefore quite a novice and apologize if my question is totally banal and/or stupid and/or asking in the wrong place.

    I want to be able to merge content from several documents on my front page (which I’ve made a container).

    I think the way to do this is using a snippet. I have therefore been booking for snippet to modify (I’m horrible at php).

    I’ve found (LastPublishedRedirect) http://modxcms.com/extras/package/?package=232 and am trying to modify it to my needs:

    ----
    $docid = (isset($docid))? $docid: $modx->documentIdentifier;
    
    $children= $modx->getActiveChildren($docid, 'pub_date', 'DESC');
    if (!$children === false) {
        $firstChild= $children[0];
        $firstChildContent= $modx-> documentContent($firstChild['id']);
    } 
    
    return $firstChildContent;


    ----

    This doesn’t work (but you can get the first child’s url by substituting documentContent with makeUrl - I’m, however, not interested in a front page of urls).

    I would be grateful for any and all help or pointers in the right direction.

    (I’m using MODx Revolution 2.0.5-pl (traditional))

    Regards

    jgj
      • 3349
      • 126 Posts
      I would push you towards the Ditto snippet - it should provide you with what you are looking for...

      http://wiki.modxcms.com/index.php/Ditto

      http://ditto.modxcms.com/

      Hope so!

      bS
        • 14104
        • 4 Posts
        Thx for the quick reply

        I had been looking at the ditto - snippet.

        And at first it seemed a little overwhelming for my purposes.

        Looking at the snippet again it clearly does what I’m looking at, and I’ll try to figur it out.

        I does, however, seem a little wierd to me that there isn’t a simple (again ditto seems a little overwhelming to me - this might just be me loosing focus) way to pull together content from a couple of ressources whose ID I know (ie. can hardcode in a snippet if need be).

        - Hope that made sense -

        But thx very much for the push.

        regards
          • 3749
          • 24,544 Posts
          If you’re using 2.0.5, you should use the getResources snippet instead of Ditto. Ditto is deprecated in Revolution, but getResources uses pretty much the same parameters.

          You’ll need a Tpl Chunk to user to format the output, but that’s pretty simple.

          If you only want the content section from the other documents (not their pagetitles or other fields), you can create one or more Template Variables that use @DOCUMENT bindings to specify the documents. Basically, you just:

          1. Create a text-type Template Variable for each doc you want to pull in (e.g., named: page1, page2 or whatever).
          2. Put @document ## in the default value field (where ## is the ID of the doc you want).
          3. Put [[*page1]] and [[*page2]] where you want the content to appear.

          Let us know if you run into trouble.

          Welcome to MODx smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 14104
            • 4 Posts
            I seem to have solved it. Thx to your help.

            I Installed getResources.

            Created a chunk:

            TestChunk
            This is my testchunk
            [[+content]]
            [[+pagetitle]]
            more
            [[+tv.ShowArchive]]
            [[+tv.ShowHome]]


            Created two Template Variable (ShowArchive and ShowHome - with default values 1 and 0 respectively)

            And then posted the following code on my Homepage:

            [[!getResources? &parents=`4` &tvFilters=`ShowHome==YEAH` &includeContent=`1` &tpl=`TestChunk` &includeTVs=`1` &processTVs=`1`]] 


            My archive page/container has the id=4. And in my test post I overwrote the default value 0 with YEAH.

            And it works.

            It, however, seems the call will fail if you filter according to default values in the TV

            ie
            [[!getResources? &parents=`4` &tvFilters=`ShowHome==0` &includeContent=`1` &tpl=`TestChunk` &includeTVs=`1` &processTVs=`1`]] 


            will not work (not even if you overwrite the default 0 with a new 0 in the TV).

            cf: http://modxcms.com/forums/index.php?topic=56003.0 see last post.

            Is this a bug? or a feature I can’t figure out? Or (more likely) am i missing something.

            Regards

              • 3749
              • 24,544 Posts
              It, however, seems the call will fail if you filter according to default values in the TV

              I think that’s expected. TV values that match the default value are not actually saved so the filter doesn’t have anything to test them against.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting