easyrider
easyrider

Reputation: 701

What is wrong when I try to add jquery script to smarty tpl files?

It gives me blank page...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
{if $tplSeoFile}{include file="$modulePath/$tplSeoFile"}{/if}   
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Author" content="" />
<meta name="Robots" content="index, follow" />
<meta name="Revisit-after" content="10 days" />
<link rel="stylesheet" href="img/cms/css/reset.css" type="text/css" media="all" />
<link rel="stylesheet" href="img/cms/css/960.css" type="text/css" media="all" />
<link rel="stylesheet" href="img/cms/css/master.css" type="text/css" media="all" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

    //Default Action
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active content
        return false;
    });

});
</script>


</head>

Upvotes: 5

Views: 5847

Answers (3)

I'd rather use {literal}{/literal}, much easier.

Upvotes: 2

cromestant
cromestant

Reputation: 660

A stated here you need to either take your code to an external JS script or make Jquery in noconflict mode! its quite simple, change $('') with jQuery('')

Upvotes: 0

karim79
karim79

Reputation: 342635

You need to enclose it in {literal} tags otherwise smarty will try to interpret stuff within curly braces in your JavaScript code, leading to catastrophic failure and potentially a white page of death:

{literal}
<script>
$(document).ready(function() {

    //Default Action
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active content
        return false;
    });

});
</script>
{/literal}

See http://www.smarty.net/docsv2/en/language.function.literal.tpl

Upvotes: 4

Related Questions