-
- 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
<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.
-
- 137 Posts
Quote from: sottwell at Jun 09, 2016, 01:37 PMYou 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>
-
- 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.
-
- 137 Posts
Quote from: Bruno17 at Jun 09, 2016, 02:58 PMFor 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>
-
- 137 Posts
Quote from: miomir.dancevic at Jun 09, 2016, 04:51 PMQuote from: Bruno17 at Jun 09, 2016, 02:58 PMFor 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>