We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30837
    • 20 Posts
    Okay, so I have a site that has a main content area, followed by three ’blocks’ for ’banners’. Each banner needs to link to a document on the site.

    So my thought was to create a "Banners" container, in which I could place one document for each banner... TV’s for the image and the document ID that it should link to. No problem.

    My problem comes when I want to make it easy for the end-user, a typically non-techy, to go in and change each banner for each page... I thought about setting up a TV that is bound to all the children of the "banners" container, but I don’t know how to do that. I tried running a ditto call with || delimiters in the TV but you can’t do that evidently.... and I can use an @document binding, but then it would be hard coded, no?

    Any help would be greatly appreciated.
      • 21257 MODX Staff
      • 730 Posts
      With a nod to David Bunker, who is a veritable fountain of knowledge on various MODx tricks (along with many many others in the community) and who helped build a site for me where this solution was used, here is how a TV can be set up to do what you’re looking for:

      * use TV type Dropdown List Menu
      * set the Input Option Values to the following:
      @SELECT pagetitle, id FROM ( (SELECT pagetitle, id, menuindex FROM [+PREFIX+]site_content WHERE parent = 21) UNION (SELECT ’@INHERIT’, ’@INHERIT’, 9999) ORDER BY menuindex) as sc
      * (replace parent = 21 in the above code with the id of your container)

      This solution allows for the inheritance of values from parent resources (documents). If you don’t need inheriting, just remove "UNION (SELECT ’@INHERIT’, ’@INHERIT’, 9999)". If you do use inheritance, I’d recommend setting the TV’s default value to @INHERIT.

        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 30837
        • 20 Posts
        Wow, never would’ve gotten that far on my own. Thanks for the help. I’ll try that out tonight!
          • 21257 MODX Staff
          • 730 Posts
          The TV I described above will output the resource id of your content.
          In order to display the content of that document in your Template, there are a number of ways, but I would try the GetField snippet. You’ll have to find and install it.
          Something like this:
          [[GetField? &docid=`[*NameOfYourGroovyNewTV*]` &field=`content` &parent=`0`]]
          

          Good luck!
            Mike Schell
            Lead Developer, MODX Cloud
            Email: [email protected]
            GitHub: https://github.com/netProphET/
            Twitter: @mkschell
            • 4310
            • 2,310 Posts
            Hey Mike you’re being far too kind smiley
            I didn’t even recognise half that code let alone write it laugh
            Glad to see you back on the forums.
              • 37747
              • 50 Posts
              Maybe I am missing the point here, hope not...

              If banner "x" links to document "y" why not have a template variable on document "y" where you upload the banner? ie. the banner that is going to link to the document is one of the tv´s for that document. Lets say the tv for uploading a banner is called "bannerImage", documents that are being linked to by a banner would need to have "bannerImage" tv which will be Input type: Image and will always serve as the banner link to the page.

              Next, on document "z" you need banner "x" to appear and of course linking to document "y".

              Make a tv called "banners" with Input Type: Text and assign it to all templates where banners should appear with a comment for the user:
              insert the id´s of the documents that you would like to link to, comma separated numbers only eg. 1,2,3

              Then use ditto to get the banners to appear on that page, ditto call would look something like this:
              (remember this is in the template of the page where you would like the banners to appear)

              [!Ditto? tpl=`insertBanner` &documents=`[*banners*]` !]


              Template, called "insertBanner":

              <a href="[~[+id+]~]" title="[+title+]">
              <img src="[+bannerImage+]" alt="[+title+] class="banner" />
              </a>


              So in the ditto call we get the document ids of the documents we want to link to and in the template we are calling the banner image, making it link to its own document.

              If you want the banner image to be different depending on the page it appears on, and not depending on the page it links to then that would be different...

                • 30837
                • 20 Posts
                That worked! Thanks for the help. I had to use some trial and error to get the code to work... for some reason it didn’t like the [+PREFIX+] code... I’m like an toddler trying to do brain surgery when it comes to advanced SQL queries, but I eventually got it to work thanks to you.

                Dangw, I think the only thing you were missing was that I wanted everything to be automatic, in other words, when the user adds a banner I wanted it to automatically populate the select list... I still stole some of your code if you don’t mind... I kept on using startID in my ditto, then I realized that you were using the ’documents’ param, once I did that, I was golden...

                Thanks again. I wish this type of functionality was a little easier to implement, but I’m not complaining. Modx is a Godsend.
                  • 37747
                  • 50 Posts
                  I see, multi select drop down list where you can choose which banners to add on the page....nice touch! Glad that I was of some help even tho I missed the point slightly.