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

    All of my output modifiers worked fine until I upgraded to 2.2.8, since then they seem to be returning wrong results.

    I have a placeholder which contains a numerical value
    [[!+total]]
    , I call it uncached since it changes often.
    Then I have the following conditional statement
    [[!+total:isnot=``:then=`(<span class="results_number">[[!+total]]</span>)`]]

    which worked fine before the update and returned placeholder only if it had a value.

    So I have been trying to find out where the problem comes form and created the following statement
    [[!+total:is=``:then=`empty`:else`(<span class="results_number">[[!+total]]</span>)`]]
    which unexpectedly returned "empty", meaning that the placeholder is empty. This is not true as I placed the [[!+total]] placeholder right outside the statement and it returns a value every time.

    My question is, what has changed since 2.2.4 which may affect the conditional statements?
    I was checking change log and didn't find anything particularly interesting regarding output modifiers.

    My guess is that for some reason Modx is gets an empty placeholder due to the order of elements which it parses, may it be right? [ed. note: ellipsis_89 last edited this post 13 years, 3 months ago.]
      • 40553
      • 42 Posts
      I have conducted some more tests and here are the results alongside with brief description of my page elements.

      1.Template (containing title with [[!+total]])
      2.Page containing Gallery snippet setting the [[!+total]] placeholder

      The order of things would explain why I my conditional placeholder didn't work, it was called before it was generated right?
      Not entirely, since I am able to retrieve it in page title but I'm not able to use conditional statements refering to its value in that page title and I don't understand why. Not to mention that it used to work fine before the update
        • 3749
        • 24,544 Posts
        The parsing order of tags is complex and I don't pretend to understand it, but making a placeholder uncached defers its processing, so there's a fair chance that it hasn't been parsed at the time you're trying to use it or that (in spite of being uncached) it was parsed before that placeholder was set.

        Or, it might be a bug. wink

        Using it more than once on the same page might also complicate things.

        A look at the resource cache (core/cache/resource) might help.
          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
          • 40553
          • 42 Posts
          I see. I even tried caching it and in both cases I was able to print it's value out, yet when placed in a conditional statement, it always returns empty value.

          I tried all of the available modifiers such as
          eq, is, greaterthanorequalto, islowerthan
          but with no luck.

          As an ok solution for now I decided to place Gallery snippet at the top of the page, then the [[!+total]] and a brand new placeholder holding the output of the Gallery at the end. This way a template which uses Gallery still displays the total number of images in the header, while showing actual images on the bottom of the page.
            • 3749
            • 24,544 Posts
            Was it in the Gallery Tpl chunk when it didn't work?
              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
              • 40553
              • 42 Posts
              It was placeholder belonging to the Gallery snippet
              gallery.total
              , yet it was not placed in a Gallery Tpl chunk as I didn't have a need to display it alongside every image, I had to place the total number of images once at the top of the page.
                • 3749
                • 24,544 Posts
                OK, but then why is your placeholder +total and not +gallery.total?

                Also, Gallery may be using str_replace to replace that "placeholder" in the output rather than setting a generic placeholder that can be used elsewhere on the page. I don't use Gallery, so I'm only guessing.
                  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
                  • 40553
                  • 42 Posts
                  I was actually checking both total and gallery.total and both of them behave the same way.
                  While total is my own placeholder with the same value as gallery.total created at the end of the snippet.

                  I will check for str_replace but as far as I remember Gallery setts a placeholder for main data such as total amount, gallery name and so on.
                    • 38705
                    • 101 Posts
                    Maybe [[+total]] is also generated by something else like the gallery?

                    What happens if you change the name op the placeholders from "total" to "specialtotal" and call this placeholder in your conditional?

                    just guessing....
                      Addict since 2012....
                      • 40553
                      • 42 Posts
                      Good guess, yet I already tried it with custom placeholder, same result.

                      Its actually quite tricky and I have been experiencing this problem for the second time now, for some reason placeholders are not always read correctly when in conditional statements.