CSS along with PHP
Posted: Sun Jul 24, 2005 6:23 am
I was always wondering how do forums get their template into PHP. What is the best way you know to implement CSS into PHP code, or to call a CSS document out of a PHP one?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<link href="e;css/style.css"e; rel="e;stylesheet"e; type="e;text/css"e; />Code: Select all
<?php
// session, $_GET and $_POST stuff first
// functions also here
include('inc/page_start.php'); // Which includes <head> and common <body> parts
//then normal page generation by print
print'whatever';
//or if some conditions are to be met
if(condition){
output_function_call();
}else some_other_output_function();
//and then common page ending
include('inc/page_stop.php');
?>Code: Select all
{include file="e;meta/doctype.tpl"e;}
{include file="e;meta/header.tpl"e;}
Do some stuff here.
{include file="e;meta/footer.tpl"e;}Code: Select all
<?php
//Some begining Code
?>
<html>
<head>
<title>Your Title</title>
<link type="text/css" rel="stylesheet" href="style.css" title="style">
</head>
<body>
<?php
//Some more PHP
?>
<!-- Some HTML -->
<!-- PHP doesn't have to take up a whole block either, you could do it inline with HTML tags like: -->
<table>
<tr>
<td>Name:</td>
<td><?php echo $name; ?></td>
</tr>
<tr>
<td>Email:</td>
<td><?php echo $email; ?></td>
</tr>
</table>
</body>
</html>This was the most useful yetAmbush Commander wrote:With Smarty, it's something like:
USE TEMPLATING SYSTEMS! WHOO!Code: Select all
{include file="e;meta/doctype.tpl"e;} {include file="e;meta/header.tpl"e;} Do some stuff here. {include file="e;meta/footer.tpl"e;}
Code: Select all
<page>
<cssfiles>
<file>/styles/style1.css</file>
<file>/styles/sub.css</file>
</cssfiles>
</page>Code: Select all
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="e;http://www.w3.org/1999/XSL/Transform"e; version="e;1.0"e;>
<xsl:template name="e;head"e;>
<head>
<title><xsl:value-of select="e;//page/title"e;/></title>
<xsl:for-each select="e;//page/cssfiles/file"e;>
<link rel="e;stylesheet"e; type="e;text/css"e; href="e;{.}"e; />
</xsl:for-each>
</head>
</xsl:template>Code: Select all
<html>
... whatever ...
<div id="e;main"e;>
ї#contents#]
</div>
... whatever ...
</html>Code: Select all
<?
require_once("class.php");
disp('header');
echo ('Welcome to my amazing web site');
disp('footer');
?>As with all things, you need to invest time to learn it.This method is similar to a lot of the xml based templating systems people use except my way does not require me to think as much and in turn my brain doesn't hurt.