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

    I list resources with getResources. In the getResources &tpl I got this:
    [[!If?
    &subject=`[[+tv.isnew]]`
    &operator=`gt`
    &operand=`7`
    &then=`[[$tplStatusB]]`
    &else=`[[$tplStatusBnew]]`
    ]] 


    tv.isnew ist a date TV.
    The issue is that it list only the first resource. But it lists the first(latest) resource so many times that resources are.
    (sorry guys for my bad english, hope you understand)

    Is it NOT possible to work with the IF-Snippet within a getResources tpl-chunk?
      • 1778
      • 659 Posts
      You can try with input/output filters instead of IF snippet...
      something like (assuming your TV is called "isnew")

      [[*isnew:gt=`7`:then=`[[$tplStatusB]]`:else=`[[$tplStatusBnew]]` ]]
      


      Hope this helps
        • 8694
        • 61 Posts
        Hi Anso,

        this bring me the same result.
          • 1778
          • 659 Posts
          Maybe a problem because your TV is a date... I tried with the input/output filter I gave you, but with a "basic" TV (text).. I put some value in it (once 9, once 3 for testing, and the output is fine)...

          BTW if your ’isnew’ tv is a date TV , it contains a date not a number. I cannot see how this tv value can be "7" (or what you number you want)...

          for example with the today date :
          [[!*isnew:gt=`2010-08-19`:then=`Later`:else=`Before` ]]
          


          Will display "Before" if the date in the TV is before today (2010-08-15 for example) and display "Later" if the date in the TV is a future one (2010-09-09 for example)

          Hope this helps
          Cheers
            • 8694
            • 61 Posts
            Hi Anso,

            I test ist with a date-TV because before I try it via a snippet. And that cause the same problem.
            I wrote a snippet that return a number how old (in days) is the document.

            In the beginning I try this:
            [[!If?
            &subject=`[[getDateDif]]`
            &operator=`gt`
            &operand=`7`
            &then=`[[$tplStatusB]]`
            &else=`[[$tplStatusBnew]]`
            ]] 


            The TV was only a test. I try the snippet inside a dicument and it worked fine. Maybe ist does not work inside a chunk?

            Just in case, here is the snippet:
            // ID of the current resource 
            $doc = $modx->getObject('modResource', $docID); 
            
            // Get creation date of the resource
            $date1 = $modx->resource->get('createdon'); 
            
            // Read current time 
            $date2 = date("Y-m-j g:i:s"); 
            
            // Convert strings into timestamps an calculate the difference 
            $days = Round(((strtotime($date2)-strtotime($date1))/86400), 0) ; 
            
            return $days; 
              • 29861
              • 59 Posts
              Just a quick guess: try to uncache your snippet: [[!getDateDif]]
              I always have surprise with the cached elements.
                • 1778
                • 659 Posts
                Did you try :
                [[!getDatDif:gt=`7`:then=`Older`:else=`Younger` ]]
                


                I did not tried it, but if your snippet works when it’s called in a resource, using Chunks is not a problem.... As said by Thithi call your snippet uncached by putting an exclamation mark at the start of the call
                  • 8694
                  • 61 Posts
                  I try this:
                  [[!If?
                  &subject=`[[!getDateDif]]`
                  &operator=`gt`
                  &operand=`7`
                  &then=`[[$tplStatusB]]`
                  &else=`[[$tplStatusBnew]]`
                  ]] 


                  Bit always the same. It give me only the first resource ...many times.

                  An when I try this:
                  [[!getDateDif:gt=`7`:then=`Older`:else=`Younger` ]]
                  

                  There is no output.
                    • 1778
                    • 659 Posts
                    Hello,
                    Not sure of that... just a thought...

                    In your snippet "getDateDif", instead of returning $days, what if you set a placeholder "nbofdays" like this
                    ...
                    // Convert strings into timestamps an calculate the difference 
                    $days = Round(((strtotime($date2)-strtotime($date1))/86400), 0) ; 
                    
                    $modx->setPlaceholder('nbofdays',$days);
                    return;
                    
                    


                    Then you can act with the placeholder in the IF snippet or with the output filters something like:

                    //with IF snippet
                    [[!If?
                    &subject=`[[+nbofdays]]`
                    &operator=`gt`
                    &operand=`7`
                    &then=`[[$tplStatusB]]`
                    &else=`[[$tplStatusBnew]]`
                    ]]
                    
                    //with output filters
                    [[+nbofdays:gt=`7`:then=`Older`:else=`Younger` ]]
                    


                    Test it with simple values like "Younger" and "Older" instead of your chunks... If it works then try with your chunks... It can also be a problem with one of the chunks ($tplStatusB), what is the code in the chunks ?

                    Cheers
                      • 8694
                      • 61 Posts
                      Hi,

                      I try it with the placeholder like you said.
                      But the same result. undecided

                      The chunk tplStatusB is only for formating the output. When I use getResource directly with the chunk (without IF or inout output filters) ist works.
                      Only if i try to use IF or the input/output filters it hangs. I think it is not possible to use IF inside a chunk. (of getResources)
                      Can it be a bug?

                      In case, here ist the chunk:
                      <div class="box">
                           <a class="pop" href="[[~[[+id]]]]">
                                <img src="[[+tv.cover]]" width="100" height="141" /><br /><br />
                                <strong>[[+tv.firma]]</strong><br />[[+tv.beschreibung]]
                           </a>
                      </div>