We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4058
    • 17 Posts
    I am trying to use Ditto and XML to pass a page-specific image to my flash header. I am stuck on the logic, however.

    This is what I have so far.

    Each page of my web site has a template variable called "section-image" where I can upload a page-specific image.

    I have a chunk named xmlFlashTpl which is setup to grab the "section-image" and converts it into an XML format.

    I have a single xml document (a MODx document in my tree that I will refer to as ’XML document’) that my flash file references to pull the XML. Within this document I am using Ditto to return my chunk xmlFlashTpl with the section-image.

    Up to this point everything is functional. My problem is I have to hard-code an ID into my Ditto snippet (in the XML document NOT the page being viewed). Instead I need that ditto call from my XML document to grab the id of the current page being viewed and replace the id in the XML document’s ditto call.

    It seems this approach is a dead-end unless I’m missing something obvious.

    I can change my XML document’s ditto call to whatever ID I want and it will successfully pull that page’s section-image.

    How do I pass my current page’s ID to another page’s Ditto call &documents variable? Or is there a better way to do this?
      • 4058
      • 17 Posts
      Further, I should note that the only necessity I have at the moment is to change this ID in my Ditto call based on what page the user is viewing.
        • 26401
        • 247 Posts

        I have a chunk named xmlFlashTpl which is setup to grab the "section-image" and converts it into an XML format.

        I don’t really know the details of what you’re trying to achieve, but what I’ve done in the past is used flashvars to directly juice the swf with the content. It works great for small stuff, and doesn’t require you to worry about loading an xml.

        I’ve adjusted my template to have the necessary code to do that part, but it can be done through a chunk or a snippet
          • 4058
          • 17 Posts
          What I am trying to do is have MODx generate a single XML document and have the document change dynamically depending on which page they are on. When someone lands on the home page, I want the Ditto call from my XML document to change its value to &documents=`1` and then feed the XML document the appropriate values from my section-image TV.

          In this way I can serve large amounts of XML and have it change between pages through the use of TVs and fully interact with flash.

          I am thinking maybe another template variable with an @eval binding to grab the id and inject it into the ditto call? I’m not sure that will even work.

          Perhaps flashvars would be a better approach. Would you mind sharing how to make that work?
            • 4058
            • 17 Posts
            I’m stumped. undecided

            Perhaps I can simplify it some...

            I want my XML document to have something like:

            [[Ditto? &documents=`[*pageid-tv*]` &tpl=`xmlFlashTpl`]]

            I would like for my [*pageid-tv*] to change to whatever page id I’m actually viewing instead of simply returning the XML document’s ID like I would if I were to place [*id*] there.

            Any ideas?
              • 21257 MODX Staff
              • 730 Posts
              The problem is that your XML document is being called by the Flash movie, which sits on an arbitrary page. The XML document can’t know, and it’s Ditto call can’t know, through simple MODx mechanics, what page id the Flash movie client is sitting in.

              One approach would be to pass the page’s [*pageid-tv*] to your Flash movie as a flashvar, then when the movie requests your XML document, it passes it in the query string. Then you could write a tiny custom snippet to embed in your Ditto call to deal with retreiving and sanitizing the value from the query string.

              [[Ditto? &documents=`[[GET?param=`pageid-tv`]]` &tpl=`xmlFlashTpl`]]
              


              where the snippet named GET might look something like

              <?php
              $val = $_GET[$param];
              // recommend checking $val for valid data..
              return $val;
              ?>
              


              I can’t help with how to get the flashvar into your XML request inside the movie though.

              A second approach might involve analyzing the HTTP_REFERER of the request in your snippet to figure out the value of that TV. It would mean more complex snippet logic, but it would remove the need to pass the TV through the Flash movie.
                Mike Schell
                Lead Developer, MODX Cloud
                Email: [email protected]
                GitHub: https://github.com/netProphET/
                Twitter: @mkschell