Re: Template style question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



HI All,

Here is what I have done for now.

<template file snippet>
<html>
<head>
<title>title</title>
[[header]]

[[sql sql="select user, level, ts from users order by user"]]
<table border=1>
<thead>
<tr><td>User</td><td>Clearance</td><td>Timestamp</td></tr>
</thead>
<tbody>
<tr><td>@#user@#</td><td>@#level@#</td><td>@#ts@#</td></tr>
</tbody>
</table>
[[footer]]
</html>

</template file snippet>

Fist I preg_split the template on each tag designed for the template
(i.e. [[tagname attribute="value"]]).

Second, I loop through the array and if the element is pure html it
prints the line.  The lines of [[tagname]] I put the tag through a
preg_match_all() and get all of the attributes and set
$ATTRIBUTES['name']="value".

Each tag has a corresponding tag.dat file which can access the
$ATTRIBUTES array.  In the .dat file I set $TAG as an array to hold
various information about the tag that the parsing class will need to
know.

The tag.dat file will pass back any information, such as results of
SQL queries to $PASSBACK.

Once the code has been included it sees that in this instance there is
a tag with data to be imprinted so then it searches for a line with
<tr><td>@#col1@#</td><td>@#col2@#</td></tr> and then it loops through
the SQL results and replaces each @#col@# with its appropriate data.

Then it prints the result and then the HTML is displayed.

It stops going through the template array when it finds another tag
starting with "[[sql".  This way I can have more than one table
imprinted onto a page.

The only problem with what I have is that it only works for data being
imprinted into a table unless it is a single item being imprinted, for
which I have a seperate tag, and then it will.

This does the trick for what I have going on now but what might be
nice is to modify this so I can list the data delimited with <br /> or
put in a <li>.  I will work on this later.  For the project I am
working on I have done all that is required as far as the template
goes.  I will be able to use the template class in a number of other
apps so I will be extending it.

The biggest reason I am comming up with my own is because I want to be
able to use it under any circumstance with no regard to any term or
condition of any license and that my class is farily small with only a
very very little chance of something breaking because I couldn't find
some obscure documentation.

I wanted to avoid

What do you think?

I may rethink what I  have going on and put [[imprint]] and
[[/imprint]] tags around the data itself and then everything will get
parsed.  I am trying to avoid that as it adds a few more key strokes.

I am going to review the pear template classes some more and get some
more ideas.

Thanks and 73,


--
Leonard Burton, N9URK
leonardburton@xxxxxxxxx


"The prolonged evacuation would have dramatically affected the
survivability of the occupants."

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux