User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion

Reply
Thread Tools Display Modes
Unread 30 Jan 2004, 14:24   #1
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Using templates for a website

I'm talking about the thing that these forums use, a template for layout and stuff, with all the HTML, and have PHP fill it with the actual content. I can work out the part with single items, like a menu. Put a [MENU]-tag somewhere and do a str_replace. But how does this work for repeating thingies (can't think of a word for it) like for example a post. There a number of posts in this thread (soon hopefully ), each with the same repeating HTML-code, but different content. How do they model this in the template file? And how do they handle it in the PHP code?

TY
__________________
"Yay"
Structural Integrity is offline   Reply With Quote
Unread 30 Jan 2004, 19:09   #2
Deathjam|wee
Weeeeee
 
Deathjam|wee's Avatar
 
Join Date: Oct 2003
Location: leeds
Posts: 586
Deathjam|wee has a spectacular aura aboutDeathjam|wee has a spectacular aura aboutDeathjam|wee has a spectacular aura about
Re: Using templates for a website

is it just me or did that make no sense
__________________
:gollum: :gollum: :gollum: :gollum:

One load of gollums is enough for anyone.Ta
DM.
Deathjam|wee is offline   Reply With Quote
Unread 30 Jan 2004, 20:30   #3
Add
Registered User
 
Join Date: Feb 2001
Posts: 442
Add will become famous soon enoughAdd will become famous soon enough
Re: Using templates for a website

that's the stupid thing with templates and php, you will end up having to write another language basically with if statments and loops etc so really it's just not worth it...
__________________
Trust in my Instinct
Add is offline   Reply With Quote
Unread 30 Jan 2004, 20:41   #4
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Re: Using templates for a website

Quote:
Originally Posted by Deathjam|wee
is it just me or did that make no sense

euh...

One has:
- a template file, containing all HTML code
- a php file, placing the actual content in the page

- php file loads template file
- Where for example it says "[MENU]", the php inserts a menu. Where it says "<img src=[BANNERFILE]>", the php inserts a picture with a banner. Technically seen this happens with a str_replace().

Right, so one has content and layout/make up separated.
I think the phpBB forum works with template files so you can have a number of different templates to change the look of the forum.

OK, what I was wondering how this works for repeating items. For example posts in a thread of a forum. You can't just put "[post]" in the template because after one str_replace() it'd be gone. I'd like every [post] to use the same templated HTML-code, and I can't think of a way.

So, how does this work?
__________________
"Yay"
Structural Integrity is offline   Reply With Quote
Unread 30 Jan 2004, 20:44   #5
Leshy
Mr. Blobby
 
Leshy's Avatar
 
Join Date: Nov 2000
Location: Belgium
Posts: 8,271
Leshy has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Leshy has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Leshy has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Leshy has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Leshy has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Leshy has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Leshy has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Leshy has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Leshy has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Leshy has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Leshy has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Using templates for a website

By pulling all posts out of the database that have a certain threadID, and then looping through a function which joins the HTML-code for a post and the actual post itself, until it's had all the posts it queried from the database?
__________________
http://www.leshy.net
Leshy is offline   Reply With Quote
Unread 30 Jan 2004, 20:53   #6
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Re: Using templates for a website

Quote:
Originally Posted by Leshy
By pulling all posts out of the database that have a certain threadID, and then looping through a function which joins the HTML-code for a post and the actual post itself, until it's had all the posts it queried from the database?
Ofcourse, but how do I model this in the template file?
__________________
"Yay"
Structural Integrity is offline   Reply With Quote
Unread 30 Jan 2004, 21:22   #7
Dave
Infallible
 
Join Date: Feb 2001
Location: Milton Keynes, UK
Posts: 604
Dave is an unknown quantity at this point
Re: Using templates for a website

http://smarty.php.net
Dave is offline   Reply With Quote
Unread 31 Jan 2004, 02:58   #8
meglamaniac
Born Sinful
 
meglamaniac's Avatar
 
Join Date: Nov 2000
Location: Loughborough, UK
Posts: 4,059
meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Using templates for a website

Ok, this is how I'd go about doing it.

Write an example of what you want in plain HTML.
Strip out all the "one time" data (taking the forums as an example, remove usernames, titles, post-text, etc) and replace them with markers like [username], [title], [posttitle], [posttext] etc. What's left is your template definition file.
Work out some code that will replace these markers with the info from the database. Get it working on your simple example.

Once you've done that, it's a (relatively) simple job to scale it up to process all the posts in a thread.

Easier said than done I know, but it shouldn't be impossible.
__________________
Worth dying for. Worth killing for. Worth going to hell for. Amen.
meglamaniac is offline   Reply With Quote
Unread 3 Feb 2004, 15:15   #9
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
Re: Using templates for a website

The easiest way to do a diy template engine in php is using preg_replace, especially as it takes arrays of patterns. A little PCRE knowledge is required..

Code:
$patterns = array( 
      "|{name}|Uis",
      "|{title}|Uis",
      "|{image=(.*)}|Uis",
    );

$replace = array(
      $name,
      $title,
      "<img src=\"images/\\1.jpg\" alt=\"\\1\" />",
    );

$output = preg_replace($patterns,$replace,$template);
If you don't trust the input data, you should examine preg_replace_callback, to allow for escaping the replacement strings before inserting into the template.
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 3 Feb 2004, 17:51   #10
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Re: Using templates for a website

Smarty looks nice, but it looks like damn much work to write my own template parser. I kind of agree with Add that it might not be worth it.
I'm going to have to see what I'm going to do with this.
__________________
"Yay"
Structural Integrity is offline   Reply With Quote
Unread 3 Feb 2004, 18:09   #11
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Using templates for a website

Generally I make a PHP file that gets require_once'd every page that exposes a simple function for each type of block of formatting needed. So generally I've got a getHeader( $replaceArray ), getFooter( $replaceArray ), $getMenu... etc as required.

When I need to do repeating items, I just keep calling something like getPost( ... ) say if I were doing a forum-type thing or a comment system or whatever. Then you have a nice simple replace loop present in each of those functions that takes the associative array $replaceArray that you're supplying to it, foreach's the keys of the array and replaces them with the values then returns the parsed result as a big string. Then you just dump that to either a buffer or just straight echo it out and bingo.

For instance, something like

Code:
function getRepeatingItem( $parseArray ) {
  $toReturn = '<tr><td style="title">#ITEMTITLE#</td><td style="content">#ITEMCONTENT#</td></tr>';
  foreach( $parseArray as $key => $value )
    $toReturn = str_replace( $key, $value, $toReturn );
  return $toReturn;
}
then you keep calling getRepeatingItem for every post you get out of a db or from a file or whatever you're doing supplying it with an array formed from a combination of placeholders you decide and info from the DB.

Or you could split the keys and values into two arrays and supply them as arguments to a single str_replace and let PHP get on with it, it'd probably be more efficient that way.

Note, haven't tried that code, it'll be by the grace of God if it actually runs. It would also assume that you have some kind of startRepeatingItems and endRepeatingItems functions defined to start and close-off the table that those items will reside in.
__________________
You're now playing ketchup

Last edited by pablissimo; 3 Feb 2004 at 18:21.
pablissimo is offline   Reply With Quote
Unread 3 Feb 2004, 20:03   #12
Dave
Infallible
 
Join Date: Feb 2001
Location: Milton Keynes, UK
Posts: 604
Dave is an unknown quantity at this point
Re: Using templates for a website

Quote:
Originally Posted by Structural Integrity
Smarty looks nice, but it looks like damn much work to write my own template parser. I kind of agree with Add that it might not be worth it.
I'm going to have to see what I'm going to do with this.
Smarty is the parser. You simply make the templates & PHP files.
Dave is offline   Reply With Quote
Unread 10 Feb 2004, 11:24   #13
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Re: Using templates for a website

Hi guys, thought I'd drop by and see how the world was

SI: Mambo Open Source is a CMS that works pretty much as Pab described. Well worth a look (I would say that though, I'm one of the established support gurus (no "Jeez, the support must suck!" jokes please ))
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 25 Feb 2005, 10:54   #14
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Re: Using templates for a website

I'd like to bump this subject again, as I've found a way to template parts of my site.
I'm using seperate templates to fill in repetative parts of the site. More concretely, I have a post.tpl and a thread.tpl.
The PHP will take the post.tpl in a loop and replace the corresponding tags.

Code:
-= thread.tpl=-

{HEADER}

<h2>{THREADTITLE}</h2>

{POSTLIST}

{FOOTER}
Code:
-=post.tpl=-

<h4>{POSTTITLE} by {USERNAME}</h4>
{POSTCONTENT}
<br>
So my loop takes the post.tpl multiple times filling it out with the post data, and after it composed all posts it will str_replace() {POSTLIST} with all the posts.

The problem is that I need to have a seperate template for every repeating pattern. On the other hand, I don't have to learn proper HTML/CSS at this moment because I can redesign all that later without having to fiddle in the code.

I ran into two other problems:
1) I need to put the message text in the PHP.
For example, I have the tag {ERRORMESSAGE} in the HTML. The error message is filled in depending on the result of something. For example "login failed", or "you are logged in" are two possible outcomes. This text is stored in the PHP part because the templates do not support IF/ELSE constructions.
Another limitation of this is the support of multiple languages. Because this text comes from the PHP files I'd need to change the PHP files to support multiple languages. I have something in the back of my head that involves loading lines from language files, but it sounds all too complicated.
Does any of you have an idea of doing this better? I'm not interested in making a new programming language, so I'm very keen on leaving out any logic in the templates. Still, I'd love to have a solution for the multiple language thing.

2) Global variables
In the code below you see global variables in replaceDefault(). I hate this because I need to go back to the templatemanager every time to look up what the variablename was again. Thereby, globals are evil. I have the same problem with the $USR variable that contains all user information like login data. I'm at loss how to do this differently at the moment.

Anyway, here's some code.

Template manager
PHP Code:
<?
$templatedir 
"./styles/{STYLENAME}/templates/";
$style "default";

class 
templateManager
{
    var 
$style;        // the style used for the templates
    
var $rawtemplate;    // the raw data of the template

    /**
    Constructor, does nothing ATM
    */
    
function templateManager()
    {

    }

    
/**
    Loads a template in the objects memory. See loadTemplateInString for loading details
    @param $name The name of the template. For example if a name of "error" is given the file "error.tpl" will be loaded.
    @return Returns true if the file could be loaded, or false if the file could not be loaded.
    */
    
function loadTemplate($templatename)
    {
        global 
$rawtemplate;
        
        
$rawtemplate $this->loadTemplateInString($templatename);
        if (
$rawtemplate == false)
        {
            
$rawtemplate "";
            return 
false;
        }

        return 
true;
    }

    
/**
    Loads a template from a file. The name is the filename. The file is searched in the folder as provided in the $templatedir variable.
    The file must have a .tpl extension. If no .tpl extension is provided in the name the extension is added.
    @param $name The name of the template. For example if a name of "error" is given the file "error.tpl" will be loaded.
    @return Returns a string containing the template or false if the template could not be loaded.
    */
    
function loadTemplateInString($templatename)
    {
        global 
$templatedir;
        global 
$style;
        

        
$filename str_replace("{STYLENAME}",$style,$templatedir).$templatename;
        if (
strstr($templatename,".tpl") == false)
        {
            
$filename .= ".tpl";
        }

        if (
file_exists($filename) == false)
        {
            echo 
"TEMPLATE LOADER ERROR: File does not exist (".$filename.")";
            return 
false;
        }
    
        return 
implode("",file($filename));
    }

    
/**
    Inserts another template at a certain point in the current template, replacing a tag in the process.
    If the tag can not be found the template is not inserted.
    @param $templatename The template to be inserted in the current template
    @param $tag The tag where the template should be inserted
    */
    
function insertTemplate($templatename$tag)
    {
        
$tpl $this->loadTemplateInString($templatename);

        if (
$tpl == false)
        {

        }
        else
        {
            
$this->replaceTag($tag$tpl);
        }
    }

    
/**
    Replaces a tag in the template with a certain value provided by $replace
    @param $tag The tag that needs to be replaced
    @param $replace The value with which the tag must be replaced
    */
    
function replaceTag($tag$replace)
    {
        global 
$rawtemplate;
        
$rawtemplate str_replace($tag$replace$rawtemplate);
    }
    
    
/**
    Replaces all default tags supported by the templateManager.
    - {ERRORHEADER}
    - {ERRORMESSAGE}
    - {SCRIPTSELF}
    - {PARAMVIEW}
    - {PARAMACTION
    - {FORMMETHOD}
    */
    
function replaceDefault()
    {
        global 
$rawtemplate;
    
        global 
$errorheader;
        global 
$errormessage;
        global 
$view;
        global 
$action;
        global 
$formmethod;
    
        
// {ERRORHEADER}
        // Puts in an error header replacing the tag with the contents of $errorheader
        
$rawtemplate str_replace("{ERRORHEADER}"$errorheader$rawtemplate);
    
        
// {ERRORMESSAGE}
        // Puts in an error body replacing the tag with the contents of $errormessage
        
$rawtemplate str_replace("{ERRORMESSAGE}"$errormessage$rawtemplate);
    
        
// {SCRIPTSELF}
        // The script called by the client
        
$rawtemplate str_replace("{SCRIPTSELF}"$_SERVER['PHP_SELF'], $rawtemplate);
    
        
// {PARAMVIEW}
        // The view parameter puts the variable $view in the URL as view = $view
        
$rawtemplate str_replace("{PARAMVIEW}""view=".$view$rawtemplate);
    
        
// {PARAMACTION}
        // The action parameter puts the variable $action in the URL as action=$action
        
$rawtemplate str_replace("{PARAMACTION}""action=".$action$rawtemplate);
    
        
// {FORMMETHOD}
        // Puts in the method of posting of the form (POST or GET) and uses the $formmethod variable
        
$rawtemplate str_replace("{FORMMETHOD}"$formmethod$rawtemplate);

    }

    
/**
    Replaces tags with information from the global $USR object
    - {USERID}
    - {USERNAME}
    - {USERSESSION}
    */
    
function replaceUserTags()
    {
        global 
$USR;

        
// {USERID}
        // The user ID as stored in $USR->ID
        
$rawtemplate str_replace("{USERID}"$USR->ID$rawtemplate);

        
// {USERNAME}
        // The username as stored in $USR->name
        
$rawtemplate str_replace("{USERNAME}"$USR->name$rawtemplate);
    
        
// {USERSESSION}
        // The user session as stored in $USR->session
        
$rawtemplate str_replace("{USERSESSION}"$USR->sessionkey$rawtemplate);
    }
    
    
    
/**
    Echos the template to the screen
    */
    
function printTemplate()
    {
        global 
$rawtemplate;
        echo 
$rawtemplate;
    }
?>
Login page
PHP Code:
<?
$tpl 
= new templateManager();

$tpl->loadTemplate("login");

$action $_GET['action'];

$formmethod "POST";
$loginresult "";


if (
$action == "dologin" && $USR->isLoggedIn() == false)
{
    
$result $USR->login(secureTextForDB($_POST['name']), secureTextForDB($_POST['pwd1']));
    if(
$result)
    {
        
$errorheader "Logged in";
        
$errormessage "You are logged in as {USERNAME}";
        
        
$tpl->insertTemplate("success","{LOGINRESULT}");
    }
    else
    {
        
$errorheader "Login failed";
        
$errormessage "Login failed, try again";
        
        
$tpl->insertTemplate("error","{LOGINRESULT}");
    }
}
else if (
$action == "dologout")
{
    if (
$USR->logout())
    {
        
$errorheader "Log out";
        
$errormessage "You are now logged out";
        
        
$tpl->insertTemplate("success","{LOGINRESULT}");
    }
    else
    {
        
$errorheader "Log out";
        
$errormessage "Log out failed";
        
        
$tpl->insertTemplate("error","{LOGINRESULT}");
    }

    
}

if (
$USR->isLoggedIn() == true && $action != "dologin")
{
    
$errorheader "Log in";
    
$errormessage "Already logged in";
}

if (
$USR->isLoggedIn() == false && $action != "dologout")
{
    
$action "dologin";
    
    
$tpl->insertTemplate("login_form""{LOGINFORM}");
}
else
{
    
$tpl->replacetag("{LOGINFORM}","");
}

// replace the LOGIN RESULT part
$tpl->replacetag("{LOGINRESULT}","");

// replace the field names of the form
$tpl->replacetag("{NAMEFIELD}""name");
$tpl->replacetag("{PASSWORDFIELD}""pwd1");
$tpl->replacetag("{LOGINBUTTON}""Submit");

// replace any default occurences
$tpl->replacedefault();

$tpl->printTemplate();
?>
Login page template
Code:
<table><tr id="tableheader"><td colspan="2">Log in</td></tr>
<tr id="tablerow1" colspan="2" align="center"><td>

{LOGINRESULT}

{LOGINFORM}

</td></tr>
</table>
Login form template. This is in a seperate template because I need to suppress it if the user uis already logged in.
Code:
<form action="{SCRIPTSELF}?{PARAMVIEW}&{PARAMACTION}" method="{FORMMETHOD}">
<tr id="tablerow1"><td>Name</td><td><input type="text" name="{NAMEFIELD}" size="20" maxlength="20" value=""></td></tr>
<tr id="tablerow1"><td>Password</td><td><input type="password" name="{PASSWORDFIELD}" size="20" maxlength="20" value=""></td></tr>
<tr id="tablefooter"><td colspan="2"><input type="submit" name="{LOGINBUTTON}" value="Log in" class=button></td></tr></form>
__________________
"Yay"
Structural Integrity is offline   Reply With Quote
Unread 25 Feb 2005, 11:23   #15
wu_trax
Registered User
 
Join Date: Jan 2003
Posts: 4,290
wu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet society
Re: Using templates for a website

i'd use use xml and xslt. If you have some parts that are used on different pages (like a side menu or some header) you can devide it up to a few different stylesheets and use preg_replace to put things together, but for the main part id seriously consider using xml. maybe its not as fast as preg_replace, but you get nice code that everyone understands without too much effort.
__________________
im not tolerant, i just dont care.
wu_trax is offline   Reply With Quote
Unread 25 Feb 2005, 14:05   #16
JammyJim
Godfather
 
JammyJim's Avatar
 
Join Date: May 2000
Location: England
Posts: 5,185
JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Using templates for a website

this is quite easy in ASP.
tis a simple 'loop until variable.eof'
with a 'next command' at the top.
__________________
Forum Administrator
Mail : [email protected] // IRC : #forums
__________________
It's not personal, it's just business.
JammyJim is offline   Reply With Quote
Unread 25 Feb 2005, 14:46   #17
meglamaniac
Born Sinful
 
meglamaniac's Avatar
 
Join Date: Nov 2000
Location: Loughborough, UK
Posts: 4,059
meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Using templates for a website

I have since discovered it is a simple matter of using regexs such as:

/(?i)\[url\](.+?)\[\/url\]/

which does, for example:
[url ]http://www.google.com[/url ]

and preg_replace (in php anyway)
__________________
Worth dying for. Worth killing for. Worth going to hell for. Amen.
meglamaniac is offline   Reply With Quote
Unread 26 Feb 2005, 03:50   #18
djbass
mmm.. pills
 
djbass's Avatar
 
Join Date: Apr 2000
Location: Australia
Posts: 2,152
djbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond repute
Re: Using templates for a website

It's really not that difficult making a template engine anyway, it's simple parsing at its best.

Also I think someone else already said it, but with repeating items it shouldn't require to be any different as once you encounter say a [POSTS] tag you pull a query from the DB for all post items relating to that thread display them then move on with the rest of the parsing.
__________________
CSS : the result of letting artists design something only an engineer should touch.
djbass is offline   Reply With Quote
Unread 26 Feb 2005, 13:31   #19
Flavius
 
Join Date: Jan 2002
Posts: 421
Flavius is a pillar of this Internet societyFlavius is a pillar of this Internet societyFlavius is a pillar of this Internet societyFlavius is a pillar of this Internet societyFlavius is a pillar of this Internet societyFlavius is a pillar of this Internet societyFlavius is a pillar of this Internet societyFlavius is a pillar of this Internet societyFlavius is a pillar of this Internet societyFlavius is a pillar of this Internet societyFlavius is a pillar of this Internet society
Re: Using templates for a website

check out wordpress.org

another of those CMS thingies

"the loop" looks something like this:

PHP Code:
<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
<h3><?php the_date('','',''); ?></h3>
<h4 id="post-<?php the_ID(); ?>">&raquo; <a href="<?php the_permalink() ?>"> <?php the_title(); ?> </a></h4>
<span class="meta">
By <a href="mailto:<?php the_author_email(); ?>" title="Email the author of this post"> <?php the_author() ?> </a>.
<?php _e("Filed under:"); ?> <?php the_category(','?>
</span>
<?php the_content(); ?><br />
<?php endforeach; else: ?>
<p>
<?php _e('Sorry, no posts matched your criteria.'); ?>
</p>
<?php endif; ?>
Flavius is offline   Reply With Quote
Unread 26 Feb 2005, 14:53   #20
Add
Registered User
 
Join Date: Feb 2001
Posts: 442
Add will become famous soon enoughAdd will become famous soon enough
Re: Using templates for a website

i'm sorry but i really think you are wasting your time with this. PHP is a templating engine in itself, what you are doing could be done so much easier by putting <?php echo $HEADER; ?> and <?php echo $threadtitle; ?> and then doing while(you have posts) { include('post.tpl.php'); }

as i said last year, you're using php to write another language to do something php already does.
__________________
Trust in my Instinct
Add is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Forum Jump


All times are GMT +1. The time now is 18:03.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018