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

    I have been trying to solve this one myself for a couple of days but no luck using Rev 2.6.1.

    It's a onepager site for a car garage. There is a section that should show cars for sale.

    There are different possible views for this section":

    1. Subtitle "Occasions" and below "No cars for sale!"
    2. Subtitle "Occasions" and below summary info for ex. "Tesla" "Model S" "125.000" on one line and below that another car.
    3. Subtitle "Occasion" and below details + photos of the Tesla for example.

    I am using getResources to retrieve the TV's for each car but having troubles showing 1,2,3!! I want to use the If snippet as this has helped me before but now i am stuck.

    I have 1 template and think i need to use the If snippet to call getResources for each view.

    So, 1 template. 2 documents: home and occasions. Occasions is a folder which holds a doc per car.

    I hope someone can help me.
      • 17301
      • 932 Posts
      Maybe try something like this with a custom snippet

      <?php
      
      $value = $modx->resource->getTVValue('nameoftv');
      
      if ($value == 'chunkA') {
      	$chunk = $chunkA;
      } else{
      	$chunk = $chunkB;
      }
      
      return $modx->getChunk($chunk);


      Call this on the page
      [[!mySnippet? &chunkA=`occassionsTpl` &chunkB=`occassionsInfoTpl`]]


      I assume that the photo is just a template variable which you can call into the second chunk but allow to be blank, no need for a third chunk?
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 29540
        • 58 Posts
        Quote from: lkfranklin at Jan 19, 2018, 08:55 AM
        Maybe try something like this with a custom snippet

        <!--?php
        
        $value = $modx--->resource->getTVValue('nameoftv');
        
        if ($value == 'chunkA') {
        	$chunk = $chunkA;
        } else{
        	$chunk = $chunkB;
        }
        
        return $modx->getChunk($chunk);


        Call this on the page
        [[!mySnippet? &chunkA=`occassionsTpl` &chunkB=`occassionsInfoTpl`]]


        I assume that the photo is just a template variable which you can call into the second chunk but allow to be blank, no need for a third chunk?

        My structure is: 1 maine page (template). This document has 1 children "occassions". Occasions has 1 document for each car.

        I understad what you want to achieve, but i need a third chunk?

        - chunk 1 empTypl -> if no cars for sale ->getresources:default=`No cars for sale`? This getResources call in main tpl. If "published" cars then show occListTpl with link to occDetailTpls.

        - chunk 2 -> occDetailTpls should show a complete page using TV's!
        [ed. note: tessed last edited this post 8 years, 8 months ago.]
          • 3749
          • 24,544 Posts
          I'm not totally clear on what you're trying to do, but you may not need any chunks.

          How about something like this on the occasions page (or its template):

          [[!getResources:ifempty=`No Cars for Sale`?&tpl=`myTpl`]]
          

          or

          [[!getResources:ifempty=`[[$NoCarsChunk]]`?&tpl=`myTpl`]]
            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