GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Jan-2003, 17:01
Elmseeker's Avatar
Elmseeker Elmseeker is offline
Awaiting Email Confirmation
 
Join Date: Jan 2003
Posts: 87
Elmseeker is on a distinguished road
Question

patTemplate Templating Engine!?


Well, thanks to a wonderful little patTemplate built in function called dumped I have finally figured out the basics of how to use this thing. I am still a bit stumpued however as to how to use my php functions within the template scheme, I mean, I have a function that includes different pages onto the site...this was my attempt at a rudimentary templating system of my own. Basically it uses a BUNCH of tables to create a static look at the top and left of the site while the white section on the bottom right changes depending on what url is requested, all pages go through the main page like: index.php?page=privpol will load the privacy policy in that white section, I would like to continue using this scheme within the template system if possible, if not well...no big deal, I still need to know how to call functions from within the template though...I don't really care HOW it get's done right this minute, I just need to get this site converted to templates before it gets too complex...any help would be muchly loved! Thanks folks!
  #2  
Old 11-Jan-2003, 18:59
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
If you're simply including FILES as different pages, then all you could do (without too much changes to your code) is to output the resulting html (of your include files) into a variable using ob_start() and friends...

Perhaps something like this:

PHP Code:

<?php

// amend your function to something like this where it used to print() or echo()

function IncMyFile()
{
  // some code...
  global $article;
  ob_start();
    // I donno what you used, but I am guessing a switch?
    switch( $GET['page'] ):
     case 'privpol':
      require_once( '/home/user/public_html/privpol.php' );
        break;
     case 'prevpol':
        require_once( '/home/user/public_html/prevpol.php' );
        break;
     default:
        require_once( '/home/user/public_html/homepage.php' );
    endswitch;
  $article = ob_get_contents(); //here's our article all wrapped up in a variable 
  ob_end_clean();
}

  // then we pass it to our template
  $template->AddVar( 'index', 'ARTICLE', $article );
   // 'index' for the name of the template i.e. 'index.tmpl'
   // 'ARTICLE' being the template variable in index.tmpl i.e. '{ARTICLE}'
   // '$article' the variable holding the [b]replacement[/b] data for the template variable above

?>


I really don't know if this would work since I didn't test it out but I think you get the gist of it?

TIP: Look at the patTemplate class file Elm, change all occurences of eregi() (I think it was) to preg_replace() for a NICE speed gain!
  #3  
Old 12-Jan-2003, 11:19
Elmseeker's Avatar
Elmseeker Elmseeker is offline
Awaiting Email Confirmation
 
Join Date: Jan 2003
Posts: 87
Elmseeker is on a distinguished road
Hmmm...I'll definately look into that, but I am also using patDBC for my DB Extraction layer and I now have another problem, using the tutorial on the patTemplate web site about using DB's there was something missing from it that I REALLY NEED to have...how do I pass a variable (from the db) through another function BEFORE sending it to the template engine to be parsed, like I have a date in the DB wich is a unix timestamp, I need to have that passed through the date function before being displayed and same thing with the main news, it needs to be passed through bb_decode first...
  #4  
Old 12-Jan-2003, 17:30
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
What do you mean by DB Extraction layer? If it means, using a class file to do all the db connections and such; I use my own, so I never looked nor have I had any experience using patDBC.
PHP Code:

<?php

// partial code from index.php...

$sql = 'SELECT `articleid`, `articletitle` '
          .'FROM `articles`'
          .'WHERE `cid`='.$_GET['c']
          .'ORDER BY `articletitle`';
$result = mysql_query( $sql, $conn ); // do error check etc

while( $row=mysql_fetch_row($result) ):
  $template->AddVar( 'menulink', 'AID', $row[0] );
  $template->AddVar( 'menulink', 'ATITLE', $row[1] );
  $template->parseTemplate( 'menulink', 'a' );
  // where 'menulink' is a subtemplate in 'menu'; see template code below
endwhile;
$template->parseTemplate( 'menu', 'a' );
// where 'menu' is a subtemplate of 'index'; see template code below
?>


INDEX.TMPL could look something like this

HTML Code:
<!-- index.tmpl--> <patTemplate:tmpl name="index"> <html> <head> <title>{TITLE}</title> </head> <body> <table cellpadding="0" cellspacing="0"> <tr> <td style="width:20%"> <patTemplate:link src="menu" /> </td> <td style="width:80%"> <h1>{HEADING1}</h1> {STORY} </td> </tr> </table> </body> </html> </patTemplate:tmpl> <!-- menu in index.tmpl--> <patTemplate:tmpl name="menu"> <ul> <patTemplate:link src="menulink" /> </ul> </patTemplate:tmpl> <!-- menulink in menu--> <patTemplate:tmpl name="menulink"> <li><a href="/index.php?pid={AID}">{ATITLE}</a></li> </patTemplate:tmpl>

It's hard to figure out what you mean by functions in your post, so hopefully you have some sample code we can discuss it over.

For formatting dates from MySQL, I prefer: Formatting Dates in MySQL this way. If you have better ideas, feel free to discuss them, I am also STILL learning.
  #5  
Old 12-Jan-2003, 18:54
Elmseeker's Avatar
Elmseeker Elmseeker is offline
Awaiting Email Confirmation
 
Join Date: Jan 2003
Posts: 87
Elmseeker is on a distinguished road
Hmmm...yeah I got this far, but my problem is certain rows need to be parsed by other functions BEFORE turning them into patTemplate variables, so would something like this work?:

PHP Code:

<?php

// partial code from index.php...

$sql = 'SELECT `articleid`, `articletitle` '
          .'FROM `articles`'
          .'WHERE `cid`='.$_GET['c']
          .'ORDER BY `articletitle`';
$result = mysql_query( $sql, $conn ); // do error check etc

while( $row=mysql_fetch_row($result) ):
//parsing rows before sending to template...
  $template->AddVar( 'menulink', 'AID', bb_parse($row[0]) );
  $template->AddVar( 'menulink', 'ATITLE', date( "h:iA M j Y", $row[1] ) ); //I use UNIX timestamps not Mysql...
  $template->parseTemplate( 'menulink', 'a' );
  // where 'menulink' is a subtemplate in 'menu'; see template code below
endwhile;
$template->parseTemplate( 'menu', 'a' );
// where 'menu' is a subtemplate of 'index'; see template code below
?>

  #6  
Old 12-Jan-2003, 18:56
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
sure... they would!
 
 

Recent GIDBlogA Week in Kuwait by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please list your site on my search engine jake2003 Search Engine Optimization Forum 5 18-Dec-2003 13:46
How a search engine really works (In english) jrobbio Open Discussion Forum 0 06-Jul-2003 17:13
Search engine optimization bookmarklets jrobbio Search Engine Optimization Forum 0 01-Jul-2003 14:15
Search engine optimization tips and my experiences jrobbio Search Engine Optimization Forum 3 20-Apr-2003 17:38
Workaround to make portal website search engine friendly jrobbio Web Design Forum 11 10-Feb-2003 16:25

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:01.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.