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

    I've developed a couple of sites in MODx now and usually things work as expected. Sometimes they don't and i usually end up making my own snippet as a workaround. This time though, i really want to know what i'm doing wrong. I've probably just mistunderstood something fundamental about placeholders and snippets but i'm prepared to be lectured.

    Im doing this particular if call like this;
    [[!If? &subject=`[[+totalResults]]` &operator=`GT` &operand=`0` &then=`Displaying [[+firstItem]]-[[+lastItem]] out of [[+totalResults]] total` &else=`No results`]]


    No matter what totalResults is, i always get the "No results" output. The placeholders belong to getPage if that is relevant. MODx 2.2 and If 1.1 installed

    Here's the result if i add &debug, used > operator in this case:
    Array ( [subject] => 23 [operator] => > [operand] => 0 [then] => Showing 1-20 out of 23 total [else] => No results [debug] => 1 ) string(10) "No results"


    I've also tried variations like:
    [[!If? &subject=`[[+totalResults]]` &operator=`empty` &then=`... 
    [[!If? &subject=`[[+totalResults]]` &operator=`neq` &operand=`0` &then=`... 
    

    But these work the other way and always show the &then and never the &else.

    Why izz like diz?

    Update: using the placeholders uncached makes no difference, but i found that doing a var_dump on
    [[+totalResults]]
    gives me
    string(18) "29"

    So apparently this particular placeholder has some weird hidden characters im gona try to get rid of.

    Thanks!
    // Kristian [ed. note: krills last edited this post 14 years, 8 months ago.]
      • 4172
      • 5,888 Posts
      try the placeholders uncached:

      [[!If? &subject=`[[!+totalResults]]` &operator=`GT` &operand=`0` &then=`Displaying [[!+firstItem]]-[[!+lastItem]] out of [[!+totalResults]] total` &else=`No results`]]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 38730
        • 5 Posts
        No change,

        [[!If? &subject=`[[!+totalResults]]` 
        &operator=`GT` 
        &operand=`0` 
        &then=`Visar [[!+firstItem]]-[[!+lastItem]] av [[!+totalResults]] st` 
        &else=`Inga resultat` 
        &debug=`1`]]


        debug result=
        Array ( 
        [subject] => 29
         [operator] => GT
         [operand] => 0
         [then] => Visar 1-20 av 29 st 
        [else] => Inga resultat
         [debug] => 1 ) 
        string(13) "Inga resultat"


        (Text is in swedish, sorry)
          • 33968
          • 863 Posts
          I'm not sure if the operator input is case sensitive but try 'gt' instead of 'GT'...
            • 38730
            • 5 Posts
            Tried, but it's not that. Even doing a custom snippet like
            if(intval($total) > 0)
              return 'Visar '.$first.'-'.$last.' av '.$total.' st';
            else
              return $else;

            won't work, because var_dump($total) says 'string 18' .. so there'ss some hidden characters there. Trying to figure out how to extract the actual int value, but
            preg_replace('/[^a-zA-Z0-9\s]/','', $total)

            equals into
            string(12) "totalResults"

            and
            intval($total)
            equals
             int(0)


            I really don't think i should be forced to make some javascript workaround for a simple thing like this.
              • 33968
              • 863 Posts
              'string 18' is presumably referring to the totalResults placeholder which is probably not being parsed.

              Is this If snippet nested inside a getResources tpl chunk or something like that?
                • 38730
                • 5 Posts
                No its "standalone" in a template.. Not nested in any other call.