Discussion:
[SMARTY] Including CSS
SG
2004-04-21 16:41:50 UTC
Permalink
This seems basic, but how do you include a css stylesheet
in a smarty template? I have no trouble including inline styles
using {literal}{/literal}, but including <link rel="stylesheet" href=
"../css/style.css" type="text/css"> between the <head> tags does nothing
even though
it works in a regular html page [ie, not one called via
$smarty->display()].
I've tried putting {literal} tags around the styles in the external
sheet (as well as not putting them), & importing the sheet via @ import
url or
including the file via {include file=""}, but nothing
goes. The docs indicate this is doable:

"The simplest thing is to avoid the situation altogether by separating
your
Javascript and CSS code into their own files and then using standard
HTML methods to access them. "

What am I missing? Does s/o have an example of a template that includes
a stylesheet that works? Are .conf files supposed to replace
css stylesheets? Thanks in advance,

s.
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Andras Kende
2004-04-21 16:48:55 UTC
Permalink
-----Original Message-----
From: SG [mailto:***@fabled.net]
Sent: Wednesday, April 21, 2004 11:42 AM
To: smarty
Subject: [SMARTY] Including CSS

This seems basic, but how do you include a css stylesheet
in a smarty template? I have no trouble including inline styles
using {literal}{/literal}, but including <link rel="stylesheet" href=
"../css/style.css" type="text/css"> between the <head> tags does nothing
even though
it works in a regular html page [ie, not one called via
$smarty->display()].
I've tried putting {literal} tags around the styles in the external
sheet (as well as not putting them), & importing the sheet via @ import
url or
including the file via {include file=""}, but nothing
goes. The docs indicate this is doable:

"The simplest thing is to avoid the situation altogether by separating
your
Javascript and CSS code into their own files and then using standard
HTML methods to access them. "

What am I missing? Does s/o have an example of a template that includes
a stylesheet that works? Are .conf files supposed to replace
css stylesheets? Thanks in advance,

s.
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


=------------------------------------------------------------

Hello,

I would try it without the ../ like:

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


Here is mine:

http://cart.kende.com/products.php

http://cart.kende.com/templates/products.htm :
<html>
<head>
<title> Product List </title>
<link href="/credit.css" rel="stylesheet" type="text/css">
</head>
<body>


Andras Kende
***@kende.com
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Alex
2004-04-21 17:13:58 UTC
Permalink
Why not use the

<base href="http://izvilina.ru/templates/izvilina/" />

tag to define site root, then CSS will be relative to it =)

alex
Post by SG
This seems basic, but how do you include a css stylesheet
in a smarty template? I have no trouble including inline styles
using {literal}{/literal}, but including <link rel="stylesheet" href=
"../css/style.css" type="text/css"> between the <head> tags does nothing
even though
it works in a regular html page [ie, not one called via
$smarty->display()].
I've tried putting {literal} tags around the styles in the external
url or
including the file via {include file=""}, but nothing
"The simplest thing is to avoid the situation altogether by separating
your
Javascript and CSS code into their own files and then using standard
HTML methods to access them. "
What am I missing? Does s/o have an example of a template that includes
a stylesheet that works? Are .conf files supposed to replace
css stylesheets? Thanks in advance,
s.
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Erich Beyrent
2004-04-21 17:46:25 UTC
Permalink
Post by SG
This seems basic, but how do you include a css stylesheet
in a smarty template? I have no trouble including inline styles
using {literal}{/literal}, but including <link rel="stylesheet" href=
"../css/style.css" type="text/css"> between the <head> tags does nothing
even though
it works in a regular html page [ie, not one called via
$smarty->display()].
I've tried putting {literal} tags around the styles in the external
url or
including the file via {include file=""}, but nothing
"The simplest thing is to avoid the situation altogether by separating
your
Javascript and CSS code into their own files and then using standard
HTML methods to access them. "
What am I missing? Does s/o have an example of a template that
includes
Post by SG
a stylesheet that works? Are .conf files supposed to replace
css stylesheets? Thanks in advance,
s.
In my Smarty config script, I always create something like this:

<?php

/***********************************************************************
*
* setup.php
*
* This is a setup file which defines all of the important directories
* for Smarty and the php templates.
*

************************************************************************
/

// load Smarty library files
ini_set("include_path","./php/lib/:./php/templates_c/");
require("./php/lib/Smarty.class.php");


/*----------------------------------------------------------
* Define an array of the directory structure for the site
*----------------------------------------------------------*/
class MySmarty extends Smarty
{
function MySmarty()
{
// Class Constructor. These get set with each new instance.
$this->Smarty();

$this->template_dir = './php/templates/';
$this->compile_dir = './php/templates_c/';
$this->config_dir = './php/configs/';
$this->cache_dir = './php/cache/';

// The url for the site
$root = $DOCUMENT_ROOT;

// Create an array of directories to be passed around
$this->assign('SITE', array("images" => $root."/images/",
"logos" => $root."/images/logos/",
"javascripts" => $root."/js/",
"css" => $root."/css/",
"photos" => $root."/photos/",
"sounds" => $root."/sounds/",
));

// Set to 2 for caching on per individual template
$this->caching = 2;

}

/*----------------------------------------------------------
* clearCache()
*
* This function will clear out the cache for a specific id.
* Expects one argument, the id of the cache
*----------------------------------------------------------*/
function clearCache($id)
{
if(! $id)
{
die("Cannot clear the cache - missing the id");
}
$this->clear_cache(null, $id);
}

/*----------------------------------------------------------
* clearAllCache()
*
* This function clears out all of the cache files
*----------------------------------------------------------*/
function clearAllCache()
{
$this->clear_all_cache();
}
}
?>

Then, in my php script:

include("./php/config/setup.php");

// Create a new instance of the Smarty class
$smarty = new MySmarty;

// Assign the global variables
$smarty->assign($home);
$smarty->assign($SITE);

Now, in my templates, I have access to all the paths in the config file.
They are accessed like this:

<link href="{$SITE.css}style.css" type="text/css" rel="STYLESHEET">

<img src="{$SITE.images}myimage.jpg">

and so on...

HTH

-Erich-
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Michael Delorme
2004-04-21 19:24:03 UTC
Permalink
the CSS file must be relative to the PHP file and not relative to your
Smarty template

|
|- test.php
|-css
| |_ test.css
|
|_template
|_ test.tpl

test.php
--------
<?php
...
display("test.tpl")
?>


test.tpl
--------
<html>
<head>
<link rel="stylesheet" href="/css/test.css" type="text/css" media="screen"
title="Test" />
...

or

<link rel="stylesheet" href="css/test.css" type="text/css" media="screen"
title="Test" />


and not

<link rel="stylesheet" href="../css/test.css" type="text/css"
media="screen" title="Test" />
Post by SG
This seems basic, but how do you include a css stylesheet
in a smarty template? I have no trouble including inline styles
using {literal}{/literal}, but including <link rel="stylesheet" href=
"../css/style.css" type="text/css"> between the <head> tags does nothing
even though
it works in a regular html page [ie, not one called via
$smarty->display()].
I've tried putting {literal} tags around the styles in the external
url or
including the file via {include file=""}, but nothing
"The simplest thing is to avoid the situation altogether by separating
your
Javascript and CSS code into their own files and then using standard
HTML methods to access them. "
What am I missing? Does s/o have an example of a template that includes
a stylesheet that works? Are .conf files supposed to replace
css stylesheets? Thanks in advance,
s.
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
_________________________________________
Michael Delorme
rue du pressoir
Mont July
01250 Ceyzeriat

tel/fax 04 74 47 90 20
mailto:***@delorme.nom.fr
NTF N 46° 11' 1.24800" E 5° 19' 58.29600"
_________________________________________
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
SG
2004-04-22 01:31:12 UTC
Permalink
Thanks all for the css answers. Using the path relative the the php page did
the trick.
s.
Post by Michael Delorme
the CSS file must be relative to the PHP file and not relative to your
Smarty template
|
|- test.php
|-css
| |_ test.css
|
|_template
|_ test.tpl
test.php
--------
<?php
...
display("test.tpl")
?>
test.tpl
--------
<html>
<head>
<link rel="stylesheet" href="/css/test.css" type="text/css" media="screen"
title="Test" />
...
or
<link rel="stylesheet" href="css/test.css" type="text/css" media="screen"
title="Test" />
and not
<link rel="stylesheet" href="../css/test.css" type="text/css"
media="screen" title="Test" />
Post by SG
This seems basic, but how do you include a css stylesheet
in a smarty template? I have no trouble including inline styles
using {literal}{/literal}, but including <link rel="stylesheet" href=
"../css/style.css" type="text/css"> between the <head> tags does nothing
even though
it works in a regular html page [ie, not one called via
$smarty->display()].
I've tried putting {literal} tags around the styles in the external
url or
including the file via {include file=""}, but nothing
"The simplest thing is to avoid the situation altogether by separating
your
Javascript and CSS code into their own files and then using standard
HTML methods to access them. "
What am I missing? Does s/o have an example of a template that includes
a stylesheet that works? Are .conf files supposed to replace
css stylesheets? Thanks in advance,
s.
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
_________________________________________
Michael Delorme
rue du pressoir
Mont July
01250 Ceyzeriat
tel/fax 04 74 47 90 20
NTF N 46° 11' 1.24800" E 5° 19' 58.29600"
_________________________________________
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
PHPDiscuss - PHP Newsgroups and mailing lists
2004-06-18 06:06:44 UTC
Permalink
Hi,

I am facing the same problem. i.e. problem with <link href="css/main.css"
type="text/css" rel="stylesheet" />

I tried to use { Literal } and it didn't work. I tried
<style>{literal}</style> and <style> without {literal}, they work fine.

I need help... friend.

<html>
<head>
<title>add customer</title>
<link href="css/main.css" type="text/css" rel="stylesheet" />
</head>
<body>
<table><tr><td>...</td></tr></table>....
</body>
</html>

I have my href="csss/main.css" path correct for the main.css file. It's
there.

Please help. Thanks.
Post by SG
Thanks all for the css answers. Using the path relative the the php page did
the trick.
s.
Post by Michael Delorme
the CSS file must be relative to the PHP file and not relative to your
Smarty template
|
|- test.php
|-css
| |_ test.css
|
|_template
|_ test.tpl
test.php
--------
<?php
...
display("test.tpl")
?>
test.tpl
--------
<html>
<head>
<link rel="stylesheet" href="/css/test.css" type="text/css" media="screen"
title="Test" />
...
or
<link rel="stylesheet" href="css/test.css" type="text/css" media="screen"
title="Test" />
and not
<link rel="stylesheet" href="../css/test.css" type="text/css"
media="screen" title="Test" />
Post by SG
This seems basic, but how do you include a css stylesheet
in a smarty template? I have no trouble including inline styles
using {literal}{/literal}, but including <link rel="stylesheet" href=
"../css/style.css" type="text/css"> between the <head> tags does nothing
even though
it works in a regular html page [ie, not one called via
$smarty->display()].
I've tried putting {literal} tags around the styles in the external
url or
including the file via {include file=""}, but nothing
"The simplest thing is to avoid the situation altogether by separating
your
Javascript and CSS code into their own files and then using standard
HTML methods to access them. "
What am I missing? Does s/o have an example of a template that includes
a stylesheet that works? Are .conf files supposed to replace
css stylesheets? Thanks in advance,
s.
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
_________________________________________
Michael Delorme
rue du pressoir
Mont July
01250 Ceyzeriat
tel/fax 04 74 47 90 20
NTF N 46° 11' 1.24800" E 5° 19' 58.29600"
_________________________________________
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Martín Troielli
2004-06-18 11:56:20 UTC
Permalink
Post by PHPDiscuss - PHP Newsgroups and mailing lists
I am facing the same problem. i.e. problem with <link href="css/main.css"
type="text/css" rel="stylesheet" />
your problem is the path where you´re executing the script.
Post by PHPDiscuss - PHP Newsgroups and mailing lists
Post by Michael Delorme
the CSS file must be relative to the PHP file and not relative to your
Smarty template
I tried to use { Literal } and it didn't work. I tried
<style>{literal}</style> and <style> without {literal}, they work fine.
read the manual. "Literal tags allow a block of data to be taken literally,
not being interpreted by the Smarty engine."
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...