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

    I have created a TV called "offer-categories", this TV outputs checkboxes that are assigned to a template used to create venue homepages. Each venue can belong to more than one offer category.

    I need a snippet that can grab values from TV’s on the venue template. So I need to grab [*offer-categories*], the logo path from [*venue-logo*] and the value from the first offer [*venue-offer-1*] and also the page ID for the venue in Modx.

    I then need to output these values on an offers index page thus:

    <h2>Category: Dining</h2>

    <ul>
    <li>
    <a href="[~id~]"><img src="[*venue-logo*]" alt="[*pagetitle*]" /></a>
    <h3><a href="[~id~]">[*pagetitle*]</a></h3>
    <p>[*venue-offer-1*]</p>
    </li>
    </ul>

    There are about 70 venues and they are all assigned to one or more of 5 offer categories.

    So the logic is:

    Where Ultimate Parent id = 15 > (venue category container) search through child items (venue pages) + where offer-categories TV = Dining
    Grab the above mentioned TV values and output each record set in formatted html

    Elseif offer=categories = Food To Go
    Grab TV values....

    I’ve had a look at the getTV function though I’m struggling to adapt it for my needs.

    Could anyone lend a helping hand?
      • 4172
      • 5,888 Posts
      I think you can use Ditto together with the getField-snippet
      If you have a TV in your ultimateparent ’category’

      use Ditto with something like that:
      &filter=`offer-categories,Dining,1` 

      together with getField which should return the category of the ultimateparent:
      [!Ditto? &parents=`venue-container`&display=`all`&filter=`offer-categories,[[getField? &parent=`1` &parentLevel=`0` &field=`category`]],1`&tpl=`your-ditto-tpl`!]

      I’m not sure if this works, but something like that should do it.

      Bruno
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 17412
        • 270 Posts
        Thanks Bruno,

        From your code I’m still wondering how I would grab the various TV values. Would it be something along these lines?

        
        [[Ditto?&parents=`15` &display=`all` &filter=`offer-categories,Dining,[[getField?&parent=`1` &parentLevel=`0` &field=`pagetitle,alias,venue-logo,venue-offer-1`]],`1`&tpl=`offer-format`]]
        
        


        So the above seems to say, where parent id=15, get all child item fields (pagetitle,alias,venue-logo,venue-offer-1) where TV offer-categories = Dining. And then format the output as per the template file.

        offer-format tpl:

        <ul>
        <li>
        <h3><a href="[+alias+]"><img src="[+venue-logo+]" alt="[+title+]" /><br />[+title+]</a></h3>
        <p>[+venue-offer-1+]</p>
        </li>
        </ul>


          • 17412
          • 270 Posts
          The penny finally dropped. I can do this with a pure Ditto solution as suggested by Bruno. I wasn’t aware that Ditto could grab custom template variable values without the help of something like getField.

          Anyhow this is the Ditto call I’m using and the same tpl as above:

          [!Ditto? &parents=`15` &display=`all` &filter=`offer-category,Health & Beauty,1` &tpl=`offer-format`!]


          Thanks for your help.