We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    That makes sense. Writing a complex custom snippet that processes a tree of resources is probably not the best place to begin learning PHP. wink

    You mentioned writing a snippet with such confidence that I thought you knew some PHP. smiley

    It’s probably better to try doing it with Ditto.

    Try this:

    1. If you haven’t already, create an TV to hold the image (Let’s Call it MyImage) and set the images for the various pages. Test to make sure the TV works by using a [*MyImage*] tag.

    2. Create a tpl chunk for ditto to use. Call it DittoImageTpl. Put just this code in it for now (note that this is not the same as the TV tag above - Ditto will set it as a placeholder so we need to use a placeholder tag):

    [+MyImage+]


    3. Put this Ditto call on the home page:

    [!Ditto? &parents=`0` &tpl=`DittoImageTpl`!]


    That should make the images show up on the home page. After you get them showing, you can work on formatting the output and making them links if you want. To make them links, you’d need to put something like this in the tpl chunk:

    <a href="[~[*id*]~]">[+MyImage+]</a>

      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
      • 3295
      • 19 Posts
      Thanks, I will give it a go. Technology and coding always winds up dictating my design and layout when I am one doing the coding. Typically I am just designing the front end and graphic design of the site, in this case i am doing it all. I really don’t want to the cms or code tell me what to do. I am just to dumb to learn this stuff wink but dang it i am going to give it go and try and do what is needed to get er done. The site looks awesome so far and MODX seems like a real nice tool, until now, my lack of knowledge and brain power has caught me up.

      That said, can you recommend a starting point for this snippet problem? I have tried every way with ditto to get it right but it is not going to work. It seems like it would be a fairly simple snippet, but I don’t even know where to begin, possible some other things to look at? Some tuts or information on what this snippet needs to bring it to life. Thanks a ton for you time, I just want to learn this stuff, but it is hard getting going.

        • 3749
        • 24,544 Posts
        If you just follow the steps in my message above, Ditto should produce some images on your home page. See if you can get that working and it shouldn’t be too big a step to organize the images the way you want them.
          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
          • 3295
          • 19 Posts
          I think I got it to work out.

          This is what I needed to accomplish

          1. there are 3 levels or folders - Main, Sub, Detail
          Sub is child of Main and Detail are childs of Sub. There could be as many Subs and Details as needed, in this case there are probably going to be more Subs than anything else.

          2. When a detail page is created there is a description that goes to a div and a photo, similar to a product detail page. The image needs to also go to a div on the Main page and the sub page that is its parent. I wanted this done dynamically, when a new sub page is created the image goes directly to its parents page in thumbnail form.

          On the main page I only wanted 4 image thumbnails, a preview of sorts.

          3. The sub page gets a description that gets placed in a div from the content box. This description also needed to get dynamically placed on the MAIN page in a div. Now, the child pages images of the sub in question also needed to correspond or in the layout sit next to the description on the main page.

          Ug... a puzzle of sorts. Probably makes no sense and is confusing, well I think i figured it out. Here goes.




          so the tree looks like this.

          Main (gets desc from sub and 4 thumbs (if 4 exist) from detail, 1 from each page)
          Sub(gets image thumb from each page, and also its on desc from content box)
          Detail ( gets 1 image uploaded to div)
          Detail ( gets 1 image uploaded to div)
          Sub
          Detail
          Detail
          Sub
          Detail
          etc...

          First I created template for detail that had a template variable for uploading an image to a div

          Next I created a chunk to hold the image from the TV that looked like this and named it `ditto-child-subcats` .

          <div class="grid_2"><div class="product_thumbs"><a href="[~[+id+]~]"><img src="[+product-image+]" width="140" height="112"></a>
          <span class="prod_name">[+title+]</span></div></div>


          I then created another chunk that looked like this and named it "sub-cats".
          <div id="thumbs" class="grid_12">
          <div id="bicycles" class="grid_4">
          <p class="sub-cat">[+title+]</p>
          <p class="desc-type">[+content+]</p>
          </div>
          [[Ditto? &parents=`[+id+] &orderBy=`createdon DESC` &display=`4` &tpl=`ditto-child-subcats`]]
          </div>


          On the main page I used ditto to call "sub-cats
          [!Ditto? &parents=`[*id*]` &tpl=`ditto-child-cats` &orderBy=`menuindex ASC`!]


          The trick here was using --- &parents=`[+id+]--- in the chunk sub cats and
          --- &parents=`[*id*]`--- on the main page ditto call. I think this is what allowed the images to go with the right description.

          Also by nesting the ditto call in ditto-child-subcats chunk allowed for the images 1 level deep to get used --- I think. This all really new to me and I have just been messing around trying different stuff. Anyhow it works and I am sure this was very confusing, but I have been trying to do this for a few days and I thought I would share.
            • 3749
            • 24,544 Posts
            Looks good. I didn’t think you’d get there so fast. smiley

            I’m surprised that it works without using Ditto’s &id parameter. It’s often needed when you make more than one Ditto call on the same page. Maybe you avoided the necessity by having the ditto calls in separate chunks.
              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
              • 3295
              • 19 Posts
              Well, I was sort of close before I even posted the first time, I had gotten close with Ditto but I thought the only way was to create a snippet, which I still want to do at somepoint, just need to start to learn a little php...

              What is dittos &id parameter? I will look that one up. It is working so far, I used the chunks because I needed the ditto call on the main page to dynamically ad a new desc and 4 thumbs every time a new sub section was created...

              Anyhow, if i ever get this site done, i will put up the working example.

              Thanks a ton for your time!!! Keep me motivated and pointed me in the right directions. Off to get some php books at B & N...

                • 3749
                • 24,544 Posts
                The &id parameter is just a unique Id that you assign to that Ditto instance so its placeholders won’t be confused with those from other instances on the same page. It’s just an arbitrary number you assign, so if you have two Ditto calls on the same page, you could use &id=`1` in one Ditto tag and &id=`2` in the other.
                  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
                  • 3295
                  • 19 Posts
                  Here is the page that needed that dynamic information from its child pages. The design and html is a little wack but the function is there.

                  http://tot-arrow.com/caffeinatedcyclist/dev/site/index.php?id=3



                    • 3749
                    • 24,544 Posts
                    Looks good. You probably know this, but the "follow us" RSS link at the bottom is missing the image in IE7.
                      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