We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12794
    • 6 Posts
    Hi to all,

    I’m a modx newbie in need of pointers huh ...

    What I’m trying to do: create a page that pulls information about various street addresses from a mysql database and renders them as placeholders in a google map.

    What I did so far: I created a snippet that pulls the data from the database and converts it in a xml file, and I placed it in a document. In the same document I’m writing the code (HTML + Javascript) to populate the google map from the XML file. This is the method I found on the google maps api pages. The problem is that it seems a waste of resources to pass through a XML file. I’d like to be able to use the data pulled from the database directly in the javascript code, bypassing the XML entirely.

    Is there any way to do this?

    Thank you!
    Marcello
      • 12794
      • 6 Posts
      Hi Ganesh, thanks for your reply.

      I had already seen the example you pointed out, but I still have a basic doubt: let’s say I have a snippet such as this:
      <?php
      $modx->setPlaceholder('name','Marcello');
      return;
      ?>
      


      And I’m calling it from a document that has both HTML and Javascript code. Let’s assume I want to use the placeholder ’name’ in my Javascript code. How do I do that?

      I tried some stuff
      <script>
      var name = [[name]];
      var name = [[+name]];
      .
      .
      .
      .
      </script>
      


      and many other combinations, but nothing seems to work. At this point I’m not even sure what I’m trying to do is possible...

      Thanks,
      Marcello
      • You have to make sure that the snippet is called before the placeholder is used in the raw document so the placeholder will be available.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 12794
          • 6 Posts
          Something like this?

          Snippet (called mySnippet):
          <?php
          $modx->setPlaceholder('name','Marcello');
          return;
          ?>
          


          Document:
          [[mySnippet]]
          .
          .
          some HTML here
          .
          .
          <script>
          var name = [[name]];
          var name = [[+name]];
          .
          .
          .
          .
          </script>
          


          If I try to access my placeholder from within the HTML code it works as expected, from the Javascript code it does not.

          Thanks
          • Hmm. The parser should be doing the replacement as it is. Maybe it’s a Revo thing; I don’t know much about Revo.

            (you are using Revo, right? Those being Revo placeholder tags...)
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 12794
              • 6 Posts
              Quote from: sottwell at Jul 28, 2010, 04:17 PM


              (you are using Revo, right? Those being Revo placeholder tags...)

              Yes, I’m using Revo.