We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20280
    • 16 Posts
    I’ve scoured the documentation for hours to no avail. The closest I can can come is:

    http://wiki.modxcms.com/index.php/Placeholders_used_by_MODx_Pages_and_Templates

    We want to accomplish the equivalent of this:

    $modx->setPlaceholders($fields,$placeholderPrefix);

    but for a TV, not a placeholder.

    I’ve been advised to use TVs instead of $_SESSION[], which is fine provided we can programmatically set them from snippets.

    Thanks in advance!
      • 3749
      • 24,544 Posts
      Do you want to set the value displayed for the TV on the current page, or the value of that TV in the DB for the current resource, or the default value of the TV?
        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
        • 20280
        • 16 Posts
        I think I understand what you are asking, and it would tie into bindings if I’m not mistaken.

        Essentially, we want the value to persist for the session, across many pages.

        For a concrete example, imagine the user logs in and enters an automobile model and year on the first page. He is going to get an online appraisal of the same.

        We want the make and year to persist throughout the session and to be accessible from subsequent pages.

        Think of a "session control block", coincident with how PHP’s $_SESSION would be used.

          • 3749
          • 24,544 Posts
          I’m still not clear on what you’re trying to do. Where will the value come from in each case? And do you want it to persist across pages for a single user session for the same user or does it need to be persist for other users?
            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
            • 8109
            • 128 Posts
            Sounds like you want a session variable or a cookie, not a TV.
              Revo 2.0.8-pl
              • 20280
              • 16 Posts
              The value will come from the user or from snippets that perform calculations on a combination of user input and database queries (xPDO is also on our TODO list).

              After some more searching I’m thinking $modx->getObject() may be key.
                • 20280
                • 16 Posts
                drwagner13, we have session variables now, and I’m fine with falling back on that. I assume you mean of the $_SESSION variety. They work wonderfully.

                I’m just trying to do this the "MODx way". smiley
                  • 20280
                  • 16 Posts
                  I did find this on your site, Bob:

                  [table][tr][td]Getting the value of a TV in another document is a little more tricky because the processed value of the TV can be different for each document it’s embedded in. As a result, you have to either get the resource object using the method above, or use specific methods of the TV and send along the ID of the document. Assuming that $id is the ID of the document (not the TV):
                  /* Get the TV */
                  $tv = $modx->getObject(’modTemplateVar’,array(’name’=>’MyTV’));

                  /* get the raw content of the TV */
                  $rawValue = $tv->getValue($id);

                  /* get the processed content of the TV */
                  $processedValue = $tv->renderOutput($id);[/td][/tr][/table]

                  You are the MODx warrior! laugh
                    • 8109
                    • 128 Posts
                    Sounds good, I think the confusion for you is coming form what a TV is. These are not so much about "templates" as they are about content items ("pages"). A TV is some mostly fixed bit of content (such as an item price, or a page-content author) that is not part of the normal ModX content form. You can add these TVs and extend the categories of stuff you can display on a page, how it is sorted, or what is shown on the page (for ecxample, a TV might be a checkbox that indicates wether a sidebar is displayed, or a pulldown menu to select which sidebar is displayed). TO the best of my undertsnading, TVs are not dynamic in the sense that they are written back to by any web application, at least not as a matter of course. If they change at all, they change slowly, and on a page-by-page basis.

                    What you want it something that works across many (all) pages on your site. For your application, you can use a session variable (server side). Or you can set a cookie on the user’s client (client side). The former is probably more robust, as it doesn’t require permission of the viewer.You could also store user-supplied information to a custom database table inside or outside of ModX, but that doens’t sound all that useful for your application. Seems to me the first one is what you want, and it’s as ModX as anything!
                      Revo 2.0.8-pl
                      • 20280
                      • 16 Posts
                      This is very, very helpful! Thanks a ton!

                      It validates what I’d suspected, that $_SESSION[] variables are just fine.

                      Naturally, we have an internal naming convention that will eliminate the possibility of collisions.

                      Thanks again!