We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50923
    • 137 Posts
    Can somebody post a simple example how to use snippets and maybe getresouces in external javascript?

    Like

    alert('[[++site_name]]');



    But all to be in external javascript file

    This question has been answered by sottwell. See the first response.

      <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>
    • discuss.answer
      You cannot use a snippet in Javascript. What you can do is generate Javascript with the returned values of the snippet.

      Create a resource with the content type of JS. Then you can access it like any external .js file. Use your snippets in the resource as usual, formatting its output in its tpl chunks the way the Javascript expects it to be.

      On the other hand, many Javascript apps work with the DOM, manipulating and using various HTML entities, which are easily generated by the same snippets with their tpl chunks for formatting the output.
        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
        • 50923
        • 137 Posts
        Quote from: sottwell at Jun 09, 2016, 01:37 PM
        You cannot use a snippet in Javascript. What you can do is generate Javascript with the returned values of the snippet.

        Create a resource with the content type of JS. Then you can access it like any external .js file. Use your snippets in the resource as usual, formatting its output in its tpl chunks the way the Javascript expects it to be.

        On the other hand, many Javascript apps work with the DOM, manipulating and using various HTML entities, which are easily generated by the same snippets with their tpl chunks for formatting the output.

        Can you show me simple alert i have asked?
          <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>
          • 4172
          • 5,888 Posts
          For a simple alert like that, put the javascript directly into the head. Not in a file.
          Or, like Susan said, create a resource with content-type of js with your javasript-code and call the url of that resource as js-file in your head.
          Then you can use MODX-tags, like you did.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 50923
            • 137 Posts
            Quote from: Bruno17 at Jun 09, 2016, 02:58 PM
            For a simple alert like that, put the javascript directly into the head. Not in a file.
            Or, like Susan said, create a resource with content-type of js with your javasript-code and call the url of that resource as js-file in your head.
            Then you can use MODX-tags, like you did.

            Yes but can i put that resource like

             <script src="MyResource.js" type="text/javascript"></script>


            In some template?
              <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>
              • 50923
              • 137 Posts
              Quote from: miomir.dancevic at Jun 09, 2016, 04:51 PM
              Quote from: Bruno17 at Jun 09, 2016, 02:58 PM
              For a simple alert like that, put the javascript directly into the head. Not in a file.
              Or, like Susan said, create a resource with content-type of js with your javasript-code and call the url of that resource as js-file in your head.
              Then you can use MODX-tags, like you did.

              Yes but can i put that resource like

               <script src="MyResource.js" type="text/javascript"></script>


              In some template?

              Only problem i have that this way i can not use MinifyX?
                <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>