Jump to content

using a css file with smarty template


sudhakararaog

Recommended Posts

 

in the index.tpl file which i access as http://localhost i am able to add the doctype and other tags

 

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>{$pagetitle}</title>

 

</head>

<body>

 

vale of smarty variable is {$var1}

 

</body>

</html>

 

all this works fine however when i add a link tag to call a css file as

<link rel="stylesheet" href="style.css" type="text/css" />

the code for css is

* {

margin: 0;

padding: 0;

}

body {

font: normal 12px Arial, Helvetica, sans-serif;

margin: 0;

padding: 0;

}

 

this css style is not being applied to the index.tpl when i access the page as http://localhost

 

 

how can i call the css file from index.tpl

 

also if i am using a jquery plugin i need to use a script tag to call the javascript files, how do i call these javascript file from index.tpl file

 

 

please advice.

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/178421-using-a-css-file-with-smarty-template/
Share on other sites

Direct css will need literal tags

 

{literal}
<style> {
   margin: 0;
   padding: 0;
}
body {
   font: normal 12px Arial, Helvetica, sans-serif;
   margin: 0;
   padding: 0;
}</style>
{/literal}

 

Css can be called from an exteral file like youve shown but should contain the root command

 

<link rel="stylesheet" href="/style.css" type="text/css" />

 

Make sure you refreash the page and also check to see that $smarty->compile_check  is set to true  $smarty->compile_check = true; , this will force template rebuid

 

also if i am using a jquery plugin i need to use a script tag to call the javascript files, how do i call these javascript file from index.tpl file

 

Just use the {literal} javascript here{/literal}  tags

thanks for replying

 

when i use

 

{literal}

<style type="text/css">

body{

font: normal 12px Arial, Helvetica, sans-serif;

}

 

#wrapper{

width: 900px;

margin: 0 auto;

}

</style>

{/literal}

 

this is working however if i use

 

{literal}

<link rel="stylesheet" href="/style1.css" type="text/css" />

{/literal}

 

the css file is not being called, also i tried

<link rel="stylesheet" href="c:/wamp/www/templates/template1/style1.css" type="text/css" /> the full path as with other smarty functions i had to give the entire path, even this is not working

 

how can i call the css file without writting

{literal}

<style type="text/css">

body{

font: normal 12px Arial, Helvetica, sans-serif;

}

</style>

{/literal}

 

as the code will increase in the page

 

also $smarty->compile_check = true; is already set in my index.php file

 

please advice

 

thanks

 

You wont need {literal} tags when using external style sheets only if you add the style directly

 

<link rel="stylesheet" href="/style1.css" type="text/css" />

 

Open your browser enter:

http://localhost/SITE.COM/templates/template1/style1.css

 

to see if the file actually exists, if it does youll include will work

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.