including smarty kills javascript
Posted: Fri Nov 08, 2013 5:24 pm
I have a simple javascript to rotate through images and text within a global variable. I want the text to be pulled from three other global variables, so that the original script doesn't have to be touched. This is where my problem is. I have the script inside {literal} tags, and it works on its own.
But when I escape out of literal, to drop in my global items for the variables, the script stops working.
Here's what I have:
But when I escape out of literal, to drop in my global items for the variables, the script stops working.
Here's what I have:
Code: Select all
<div id="slidertext">nothing at first</div>
{literal}
<__script__ type="text/javascript">// <![CDATA[
$(document).ready(function() {
var slidetext1 = '{/literal}{global_content name="slidetext1"}{literal}';
var slidetext2 = '{/literal}{global_content name="slidetext2"}{literal}';
var slidetext3 = '{/literal}{global_content name="slidetext3"}{literal}';
/* if these are set to this, it'll work:
var slidetext1 = '<h1>text from <span id="sample">global variable</span><h1>'; */
var newBg = ['slide1.jpg', 'slide2.jpg','slide3.jpg'];
var newContent = [slidetext1,slidetext2,slidetext3];
var path="uploads/images/slides-main/";
var i = 0;
var i2 = 0;
var rotateBg = setInterval(function(){
$('#sliderbg').css('backgroundImage' , "url('" +path+newBg[i]+ "')");
if(i==2)
i=0;
else
i++;
}, 4400);
var rotateBg = setInterval(function(){
$('#slidertext').html(newContent[i2]);
if(i2==3)
i2=0;
else
i2++;
}, 4400);
});
// ]]></__script>
{/literal}