Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 427
easyrider Avatar asked Feb 08 '11 09:02

easyrider


1 Answers

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

like image 125
karim79 Avatar answered Sep 27 '22 16:09

karim79