 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
10-24-2007, 07:44 PM
|
#21 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
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
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 guest! Please login or register.
</else>
</body>
</html>
Like that! That would be awesome ;)
Anyways, are you going to write that tutorial anyways? :)
|
|
|
|
10-24-2007, 07:54 PM
|
#22 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
10-24-2007, 11:24 PM
|
#23 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Posts: 165
Thanks: 0
|
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...
|
|
|
|
10-25-2007, 12:58 PM
|
#24 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Yea but that's why you keep the if tag as close to a HTML tag as possible.
<html>
<if condition="$testvariable">
</if>
</html>
|
|
|
|
10-25-2007, 01:54 PM
|
#25 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Posts: 165
Thanks: 0
|
... 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>
|
|
|
|
10-25-2007, 02:16 PM
|
#26 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Okey.... :/
|
|
|
|
10-25-2007, 02:47 PM
|
#27 (permalink)
|
|
The Reckoner
Join Date: Sep 2007
Posts: 437
Thanks: 22
|
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.
|
|
|
|
10-25-2007, 03:38 PM
|
#28 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Ah, nice :D
But are you writing a tutorial for your class?
|
|
|
|
10-25-2007, 03:58 PM
|
#29 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Quote:
Originally Posted by Karl
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.
|
|
|
|
10-25-2007, 04:25 PM
|
#30 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Posts: 165
Thanks: 0
|
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.....
|
|
|
|
10-25-2007, 05:29 PM
|
#31 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
10-25-2007, 06:56 PM
|
#32 (permalink)
|
|
The Wanderer
Join Date: Sep 2007
Posts: 11
Thanks: 0
|
Quote:
Originally Posted by Tanax
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.
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|