![]() |
[Request tutorial] Template class
Hey! I'm very interested in learning, but none of the tutorials I've found so far have covered the matter in a more deeper way, they've only scratched the surface. I wanna know more about how it works, and how to script it.
So I'm requesting some of you PHP pro's here on talkphp.net to make an article/tutorial on how to script an elite/1337/pro template class! |
Elite, 1337, Pro template class available at http://www.phpsavant.com. Trust me, it's a reliable class.
|
Yea, but I want my own, because it's easier to understand... I don't have a clue how to use savant.. :S
|
Well, depends on how complex you want it to be. Im planning on writing one (customized for my CMF) soon, so i might write a tutorial about it soon. ;) However, i won't make it as advanced as my class is gonna be, also since its gonna be commercial (Not alone, but with my CMF).
|
Well, really I'm happy with whatever info I can get on the subject Izym.
I'd love to read your tutorial when it's done, perhaps you can show a preview of your page later :) |
Quote:
|
The documentations on their websites sucks :S And also, the layout of the website is horrible, no offense, but I can't find almost anything on that page..
|
The problem is that a "template class" is many things for many people. The requirements for a template class can vary from project to project. Because of that, it would be nice to know what you consider should be required features (and optional/nice to have features) in your "elite/1337/pro template class".
It could end up being something as simple as the following class, or 1,000s of lines of code. PHP Code:
|
Salathe is spot on. Template files can be really extensive. However, to extend onto our simple template class, I would add the following code to store page states as well. That way you can have like so:
We create our views folder and then inside there we have our individual page folders, and then in our individual page folders we have the page states as listed above. PHP Code:
|
Well, I mean a class that allows me to change the template of the website with a click from a menu, like on this forum.. you can quite easially change the theme from this theme to another(ofcourse you have to import it etc etc.. but you get the point).
And make a management system, like in vB edit template feature in the admin cp, where you can change the template code quite easially. And they're using both php and html in the same document without any tags(don't quite understand how..), they write stuff like: if($condition['show'] == 'member') <a href="something.php">Forum index</a> And that's how I would want it! To easially be able to CHANGE the templates imported, via an admin cp. So, that's my pro/elite/1337 template class idea! :) (hard - yes, impossible - noo :D) |
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:
|
That would be awesome! :D
One thing though, how do they do this: <span id="something">Hello and welcome {username}</span> Which would outprint the username of the current logged in user.. I'm just curious(as always :D), how they can do with curly brackets instead of $username |
Well it's just a matter of preference really. In the above example, the template would be parsed and {username} would be replaced during this stage. Parsing like that can slow down templates though.
|
It's just a matter of going through the template text with
str_replace, preg_replace or similar. Again, I'm sure someone has the time to write up a tutorial or quick example but I don't today. |
Ah, okey, I get the idea.. :)
But I'll look forward to both karl's and Izym's tutorials :D |
I recently developed a small script that I am using for a small business website. I'll show the code first then describe what the function does.
template.html Code:
<html>PHP Code:
PHP Code:
Each time the loop goes around it will replace the 'placeholder' with the content. Once the loop is finished the content is displayed on the page. The script isn't perfect, but I'm new(ish) to this too ;) |
That looks nice :)
And it's not far from perfect ;) It's just that this is only got to do with the TEXT on the webpage. I want to be able to change the actual style of the page :) |
Also using Smarty would be a good choice
|
Urg, as I said earlier, I wanna use my own template class, and not some already made-ready to use- template class.
So, smarty and savant goes down .. |
Smarty seems quite easy to use tbh, but if u really wanna do your own im sure that you could build on some of the examples above, just tinker with them, its the best way to teach yourself PHP or indeed any langauge (i mean learn by example, i dont mean copy code and just use it, that would get u nowhere).
a simple smart template could be constructed like this: PHP Code:
HTML Code:
<html>simple really and it provides the much coverted seperation between logic and presentation, which makes scripts alot easier to maintain and extend. |
| All times are GMT. The time now is 12:25 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0