TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-24-2007, 07:44 PM   #21 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Well, I can't give you any other example than the template engine that vBulletin has, it's awesome.
And I know I can use smarty or savant.

But I want to code it myself, and be able to feel that I've done the template engine myself(with your help), other than using a free script.

Quote:
Originally Posted by Karl View Post
I actually wrote a class to do this exact same thing yesteday. Essentially though, it's simply a template within a template. The outter template provides the layout, such as:

PHP Code:
<html>
<
head>
<
title>$pageTitle</title>
</
head>
<
body>
$pageContent
</body>
</
html
You then render your inner template (I call them Views - from an MVC pattern), store it in a string and push it to the layout as $pageContent. I will wrire up a tutorial for a simplified version of this soon, however it wont be for a few days as I am currently busy with other things :(
Do you run this with if statements aswell?

PHP Code:
<html>
<
head>
<
title>$title</title>
</
head>
<
body>
<if 
condition="$logged">
Welcome $userinfo[name]!
Your last visit was$userinfo[lastvisit].
</if>
<else>
Welcome guestPlease login or register.
</else>
</
body>
</
html
Like that! That would be awesome ;)


Anyways, are you going to write that tutorial anyways? :)
Tanax is offline  
Reply With Quote
Old 10-24-2007, 07:54 PM   #22 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

That's what I, and many others, dislike about Smarty. In my humble opinion, it's not worth the files it's written in. Making up your own pseudo code that will be parsed by PHP may seem fun to begin with, but before you know it, you've written an entirely new programming language, and let's be honest, we don't need any unnecessary languages to learn!

In the beginning, PHP used to be like that, in fact PHP used to be shown in HTML comments and then interpreted with a C/C++ application. Thankfully it's since moved away from that area. If you want to use an if statement in your HTML, use a PHP if statement!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 10-24-2007, 11:24 PM   #23 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

I agree with WildHoney, if you need to have IF/while/foreach etc in a template, use the php form of it. Its not going to benefit you anymore than using PHP in the template...
bluesaga is offline  
Reply With Quote
Old 10-25-2007, 12:58 PM   #24 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Yea but that's why you keep the if tag as close to a HTML tag as possible.

<html>
<if condition="$testvariable">
</if>
</html>
Tanax is offline  
Reply With Quote
Old 10-25-2007, 01:54 PM   #25 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

... but thats still negligible, its still a new language to learn. And it takes extra processing time to parse the new templating functions!

Its so much easier to do:
PHP Code:
<html>
<?php
if($condition == $testvariable)
{
}
?>
</html>
bluesaga is offline  
Reply With Quote
Old 10-25-2007, 02:16 PM   #26 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Okey.... :/
Tanax is offline  
Reply With Quote
Old 10-25-2007, 02:47 PM   #27 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

not sure if you know about this, but there is an alternative syntax that you can use for your conditions, I always use this when mixing PHP with XHTML:

PHP Code:

<div>
<?php if ($something 1): ?>
   Something else...
<?php endif; ?>
</div>
I think it looks better than using the curly braces.
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
Old 10-25-2007, 03:38 PM   #28 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Ah, nice :D
But are you writing a tutorial for your class?
Tanax is offline  
Reply With Quote
Old 10-25-2007, 03:58 PM   #29 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Karl View Post
PHP Code:
<div>
<?php if ($something 1): ?>
   Something else...
<?php endif; ?>
</div>
I think it looks better than using the curly braces.
Not only does it "look better" but when you scan over your template and see a line with just <?php } ?> it can be troublesome to match up the corresponding opening brace (unless you're very, very strict about your code structure).

I use the "alternative" syntax for if, while, for, foreach... blocks almost exclusively in my template files for the reasons discussed already. It just makes life easier.
Salathe is offline  
Reply With Quote
Old 10-25-2007, 04:25 PM   #30 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

Hmm i normally use the alternative for html aswell, not sure why i said that really :s but yea, its easier to use php than it is to create your own language, parse it and make it work without any problems efficiently.....
bluesaga is offline  
Reply With Quote
Old 10-25-2007, 05:29 PM   #31 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Extending onto Salathe's post, you can also see what you're actually ending, because instead of having just a generic ending curly brace that could be an ending to anything: for loop, if statement, switch statement, etc. You have the following which tells you exactly what you're terminating:
  • enddeclare;
  • endfor;
  • endforeach;
  • endif;
  • endswitch;
  • endwhile;
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 10-25-2007, 06:56 PM   #32 (permalink)
The Wanderer
 
Join Date: Sep 2007
Posts: 11
Thanks: 0
Chaos King is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Ah, nice :D
But are you writing a tutorial for your class?
If you read the entire post, people posted different methods as solutions. There you go, many tutorials? :D

Just read over the posts, I saw some pretty basic ones in which can lend you a hand for what ever template system you are trying to develop.
Chaos King is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:04 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design