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

    First time using revo2, although a long time user of modx. So far revo2 is excellent, nice work all involved!

    I’m putting together a photograph site for myself, and have started with a blank canvas. So far, I have my basetemplate, this is pulling through some content and my thumbnail tv: [[*thumbnail]] - all displaying well

    My thumbnail tv is set to Image in the rendering type and output type. I want the class to be dynamic, and pull through the parent folder’s longtitle depending on what folder the page is in (i.e. if the photograph is an insect, the markup should look like <img src="macroPhotos/insect.jpg" class="macro" /> (with macro being the folder this page is saved in). I would have thought adding [[getResourceField? &id=`[[*parent]]` &field=`longtitle`]] to the class in the tv would work, but modx keeps stripping back the getresourcefield code when I save the tv. I’m sure I’ve used this technique on previous methods of modx, but have completely failed with revo2.

    What’s the best way to have the parent folder longtitle dynamically added to the class in the tv?

    Any help would be very much appreciated.

    4hero.

      • 121
      • 36 Posts
      just to add, it works when I add [[*parent]] to the class in the tv. A number isn’t any good though, I need the parent title sad
        • 3749
        • 24,544 Posts
        Try putting a snippet tag there:

        [[!getParentName]]


        /* GetParentName snippet */
        $parent = $modx->resource->getOne('Parent');
        return $parent->get('pagetitle');


          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
          • 121
          • 36 Posts
          Thanks, but getting a fatal error with that:
          Fatal error: Call to a member function get() on a non-object in C:\xampp\htdocs\mysite\core\cache\elements\modsnippet\26.include.cache.php on line 8


          All I want is the documents parent as a class embarrassed Spent all night on this one simple thing, and can’t even seem to find any decent reference docs for revo2 anywhere.
            • 3749
            • 24,544 Posts
            One of the resources you’re using this on is at the root and has no parent resource. No documentation is going to tell you how to get the name of the parent document for a resource that doesn’t have a parent. wink

            I’m sorry I didn’t think to build in the sanity check in the first place.

            This will prevent that:

            /* GetParentName snippet */
            if ($modx->resource->get('parent')) {
                $parent = $modx->resource->getOne('Parent');
                return $parent->get('pagetitle');
            } else {
                return 'site-root';
            }
            


            Change ’site-root’ to whatever you like for documents at the root.


              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
              • 121
              • 36 Posts
              Thanks for your help with this BobRay, but you’ll need to forgive my ignorance when it comes to php/mysql (I’m more of a front-end developer, css/html/jquery). Never had any issues putting sites together before using previous versions of modx, but revo2 has me stumped sad

              I’ve tried your latest suggestion, but the parent is still not being generated in the class (it’s outputting site-root in the home html).

              I’ll explain what I have so far:

              My folder structure is this:

              web
              Home (1) - the page I’m using to view my output from the tv
              Photographs (5) - I want to get all thumbnails from this folder using the tv
              Macro photographs (2) - long title is "macro" - there’s a couple of pages with photos in here using the thumbnail tv - all thumbnails showing ok on Home - I want all thumbs from here to have class="macro"
              Automotive photographs (6) - long title is "automotive" - there’s a couple of pages in here too - all thumbnails showing ok on Home - I want all thumbs from here to have class="automotive"

              The content of my BaseTemplate (Home is using this template):
              <html>
              <head>
              <title>[[++site_name]] - [[*pagetitle]]</title>
              <base href="[[++site_url]]" />
              </head>
              <body>
              [[*content]]
              </body>
              </html>
              


              The content of my Home page:

              [[!getResources? &parents=`5` &tpl=`chunkThumbnail` &includeTVs=`1` &processTVs=`1`]]


              The thumbnails are showing ok on Home, and the class on all thumbnails is site-root currently.

              My chunk name: chunkThumbnail

              <li class="[[*id]]"><a href="[[~[[+id]]]]">[[+tv.thumbnail]]</a></li>


              The details of the thumbnail tv:

              Variable Name: thumbnail
              Caption: 
              Description:
              Category: 0
              Lock variable for editing:
              Sort Order:
              Clear Cache on Save: ticked
              
              Rendering Options
              Input Type: Image
              Input Option Values:
              Default Value:
              Output Type: Image
              Alternate Text:
              H Space:
              V Space:
              Border Size:
              Align:
              Name:
              Class: [[getParentName]]
              ID:
              Style:
              
              Attributes:
              Template Access: BaseTemplate is ticked


              And the contents of my getParentName snippet:

              <?php
              /* GetParentName snippet */
              if ($modx->resource->get('parent')) {
                  $parent = $modx->resource->getOne('Parent');
                  return $parent->get('pagetitle');
              } else {
                  return 'site-root';
              }


              I think that’s all, my head is spinning now laugh All this just to get the parent class, I’m going insane now!

              Any further help would be excellent (assuming you aren’t sleeping by now!).

              4hero.

                • 3749
                • 24,544 Posts
                The parent is the document containing the current document in the tree.

                If your home document is at the root level of the tree, its parent is "Web" which isn’t a document at all and has no pagetitle.
                That’s why it’s returning ’site-root’. Try it on a document that has a parent.

                The tree is a hierarchy like this:

                web
                  SomePage (parent is web)
                  home (parent is web)
                      Page1 (parent is home
                      Page2 (parent is home)
                  docA (parent is web)
                     Page 1A (parent is docA)
                     Page 2A (parent is docA)
                
                

                  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
                  • 121
                  • 36 Posts
                  Hmm, seems a bit odd.

                  I’ve created a page inside folder 2 (pagetitle is macro), I’ve asked that page to get it’s parent pagetitle and display it as a class. I’m then asking the homepage to show me all thumbnails within pages and display any tv’s they may have. I would have thought the parent would be the parent of the page in the specific folder and not the page I wanted them displayed on?

                  Is there any other way to dynamically display a class then, other than me create a new tv (and template) for each image type; i.e. macro? This would mean, in my tv, I would have class="macro" in the attribute.

                  All I want is to show all thumbnails within my photographs folder and display a class on that image, depending on which folder it is saved in. For example:

                  <li><a href="#"><img src="macro/photo1.jpg" class="macro" /></a></li>
                  <li><a href="#"><img src="automotive/photo1.jpg" class="automotive" /></a></li>
                  <li><a href="#"><img src="people/photo1.jpg" class="people" /></a></li>

                  I could, of course, just hard code this (rather than using a tv), just trying to make the end result as effortless as possible?
                    • 3749
                    • 24,544 Posts
                    Quote from: 4hero at Jan 27, 2011, 03:57 PM

                    All I want is to show all thumbnails within my photographs folder and display a class on that image, depending on which folder it is saved in. For example:

                    <li><a href="#"><img src="macro/photo1.jpg" class="macro" /></a></li>
                    <li><a href="#"><img src="automotive/photo1.jpg" class="automotive" /></a></li>
                    <li><a href="#"><img src="people/photo1.jpg" class="people" /></a></li>

                    I could, of course, just hard code this (rather than using a tv), just trying to make the end result as effortless as possible?

                    What are you using to generate that list?

                    Do you have a separate resource for each photograph? If so, it might be a good job for getResources and a TV with the @INHERIT binding.

                    Have you looked at the Gallery add-on? I haven’t really used it but it may do what you want.
                      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
                      • 121
                      • 36 Posts
                      Hi BobRay, thanks again for your help.

                      I’ve had a look at the gallery, it’s not ideal for what I want to do.

                      I got this working using @inherit. Here’s how (in case anyone else wanted to know).

                      I’m going to show the latest 50 photos (of all categories) on my homepage. Here’s how they will be pulled in (parent 5 is my photographs folder, this contains sub folders with different categories; i.e. macro, automotive etc):

                      [[!getResources? &parents=`5` &limit=`50` &tpl=`chunkThumbnail` &includeTVs=`1` &processTVs=`1`]]


                      I then created a chunk named "chunkThumbnail" which contained:

                      <li><a href="[[~[[+id]]]]"><img src="[[+tv.tvThumbnail]]" class="[[+tv.tvImageClass]]" /></a></li>


                      I then created two tv’s, one called "tvThumbnail":

                      Variable name: tvThumbnail
                      Input type: Image
                      Output type: Default
                      
                      I also set the 'Template Access' to make sure this was available to my photographs template.
                      
                      Everything else was left as it is (default).
                      


                      I created another tv called "tvImageClass"

                      Variable name: tvImageClass
                      Input type: Text
                      Default value: @INHERIT
                      
                      I also set the 'Template Access' to make sure this was available to my photographs template.
                      
                      Everything else was left as it is (default).
                      


                      I then made sure my "Macro" and "Automotive" folders within my parent "Photographs (ID5)" had the appropriate class added (marco and automotive funnily enough laugh)

                      View the homepage and I now get the output I require cool

                      <li><a href="index.php?id=8"><img src="thumbnails/insect.jpg" class="macro" /></a></li>
                      <li><a href="index.php?id=9"><img src="thumbnails/motorbike.jpg" class="automotive" /></a></li>


                      Now all I need to do is go through 45000 photos and pick the ones I want to show on my portfolio...

                      Oh, and lots of css, html, jquery.. At least we now have this class issue resolved (thanks again BobRay!!)