We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42596
    • 45 Posts
    Hey guys and girls,

    I am trying to template a snippet I am writing and used the following tutorial: http://rtfm.modx.com/revolution/2.x/developing-in-modx/basic-development/snippets/templating-your-snippets

    This worked all fine and dandy apart from the fact that nowhere does it mention how to include TVs from the resources it is getting...the only thing that is getting output is the url and the pagetitle...I'm guessing you have to turn TV's on somehow as you would when making a getResources call?

    I have found other ways but nothing that works and I would like to avoid having to re-write my code as I had to do that already when I saw this tutorial and realised that it had to be done that way to template everything.

    Thanks,

    Matt
      • 4172
      • 5,888 Posts
      why can't you use getResources or pdoResources, if you want to list resources with TVs?

      If performance counts, you will need some more or less complicated joins to get TV-values, too.
      pdoResources or getResources does this automatically for you.

      It is also possible with

      $fields[$tvname] = $resource->getTVValue($tvname);


      But this would create a query to the db for each TV and each resource.

      If you need a very customized version of pdoResources for some reason, you can create it with a pdoTools-include.
      See pdoResources for an example.

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 42596
        • 45 Posts
        I'm building a car website and for each car, underneath the pictures and description etc, they want to have a "Similar Cars" feature where it shows a few cars that are similar in price...within +- $5000 and possibly required to match on other criteria as well. I have written the script which gets the correct resources but does not get the TV's for each one.

        The structure is that all of the cars are individual resources in a folder.

        Can getResources do that? I honestly didnt think you could customize it that much.

        I can get the TV's in the php and just write out the surrounding html in the snippet but one of the images needs to have some phpthumbof stuff applied to it and I dont know how to do that unless its through an output modifier so I thought I would create a chunk template for the output.
          • 36573
          • 173 Posts
          You could use a &where{} statement with pdoresourses. Example:

          [[!pdoResources?
          	&parents=`0`
          	&where=`{"price:>4000"AND:"price:<6000"}`
          ]]
          


          Not sure on the where syntax. You could also use &TVfilter.

          http://docs.modx.pro/components/pdotools/snippets/pdoresources
            Everything I know I learned on the internet. Saved me thousands in College tuition,
            • 3749
            • 24,544 Posts
            One common way to do this is by getting the price from the displayed page with JavaScript, making an Ajax call to a processor that gets the output with a query based on the price, then displaying the results with JS. The processor can use $modx->runSnippet() to get the results using getResources or pdoResources, or you could generate it yourself with custom code.

            As crecorn suggests, you can have getResources or pdoResources get vehicles within a price range, but I don't think you can base that range on the price of the current vehicle, and it sounds like that's 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