0

I'm in the process of shifting a web application from a PHP/MySQL backend to the Grails framework. However, the app has a fair bit of legacy javascript code written for it that I'd like to use with minimal re-writing. Its currently not working, and I'm not sure why.

A friend wrote a fade out slideshow script that requires an array initialized as

var images[3];
images[0] = ['path to image', 'link to somewhere', 'target'];

When writing in PHP, I just used the relative path and double quotes for the link and target, ie

images[0] = ["../images/file.jpg", "", ""]

Shifting to Grails, I want to have the slideshow visible on all pages, thus resuling in insertion in main.gsp.

I've declared the javascript link in the head as

<g:javascript src="fade_in.js" />

The way the original script worked was the image array was initalized in the script, then passed in via a function call in the body code. Since I don't know if its possible to use a Grails createLinkTo function call in a js file, I initialized the array and called the function with

<div id="slideshow">
  <script type="text/javascript">
        var images[3];
        images[0] = ["<g:createLinkTo dir='images' file='nsf.jpg' />", "", ""]
        images[1] = ["<g:createLinkTo dir='images' file='east.jpg'/>", "", ""]
        images[2] = ["<g:createLinkTo dir='images' file='usm_horz.png' />", "", ""]
        new fadeshow(fadeimages,200,118,0,8000,1,"R");                          
  </script>
</div>

According to firebug, the paths to the files is correct, but they're not showing up in the specified div position. I can see where the images should be, and its empty.

So, what needs to be done to integrate this functionality with a Grails app?

1
  • I assume your call to fadeshow passing fadeimages is a typo, since your array is named "images" ? Commented Apr 12, 2012 at 22:14

1 Answer 1

1

You can not use GSP tags in a .js file unless you have mapped the js file as gsp. You can create a gsp file eg fade_in.gsp that would declare the images array.

Eg - fade_in.gsp

<script>
   //you initialize your javascript array here - you can use all gsp tags.
</script>

And then include this gsp file in other pages that needs the images array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.