SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Template Class

  1. #1
    SitePoint Zealot imagize's Avatar
    Join Date
    Oct 2004
    Location
    Australia
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Template Class

    Hey all, im looking for a small effective template class. I DONT want something like smarty or anything like it. Just a template class that will enable me to make

    {poll}
    {news}
    {navigation}

    etc

    become other stuff.

  2. #2
    SitePoint Addict myrdhrin's Avatar
    Join Date
    Jul 2004
    Location
    Montreal
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you use PHP as your template language

    so this way

    {poll} could become <?=$template_pool?>

    and so forth and so on...

    Not a new idea. There is an article on SitePoint about it but it's a lot quicker than designing or learning another template system...
    Jean-Marc (aka Myrdhrin)
    M2i3 - blog - Remind-M

  3. #3
    SitePoint Guru
    Join Date
    Dec 2003
    Location
    oz
    Posts
    819
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    class Template
    {
        function 
    load($fileName) {
            
    $this->templateSrc file_get_contents($fileName);
            
    $this->values = array();
        }
        function 
    set($varName$data) {
            
    $this->values[$varName] = $data;
        }
        function 
    render() {
            
    $s $this->templateSrc;
            foreach (
    $this->values as $varName=> $data) {
                
    $s str_replace("{".$varName."}"$data$s);
            }
            return 
    $s;
        }



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •