Jump to content

functions and templating


soddengecko

Recommended Posts

hi all

i am 99% done on coding a link manager. just some style stuff to finish it off.

what i would like to do is use templates and remove all html from the code and use functions to help make this work and to make it easier for people to create thier own themes.

i need some help and info on how to create templates and allow users to choose the template they wish to use.

i have searched google and plenty of websites but i am not finding the information i need.

i like the way wordpress uses templates but i have no idea how to implement it.

does anyone have any ideas or resources that i could learn from?
Link to comment
Share on other sites

PHP include() is the fastest template engine! But I figure you don't want use that from the question you asked! Template engines can be done so many different ways, the PHP way is the best because PHP is already a awesome token parser. Back to your question...

You are going to have to decide how you want your template engine to work, how will you store the templates (db/io), will native PHP code embedded in a template be parsed, how will you parse the template (eval,str and preg_ functions). also some things you do will increase the applications security risk, so you have to be very careful, then other things you implement will cause a performance penalty. All in all you need to decide these things, because only you know how you have designed the rest of your application, knowing that will tell you the best way to proceed!

a basic template system might work like this!


1. top of your script, ( include an array of templates, that this page may call, then fetch all of them holding them in a template array )

You do it this way so you don't have to query the database for template, each time you use that template. (pre caching)
The same goes for flat file templates, but it won't always be case, it depends on how your storing them (single file, XML, multi files)!

2. when a code building block is done you pass those variables to your template parser, along with the template to be filled adding all that to a out container variable that holds all the building until your ready to dump that data into the main generic template for this page!

This part depends on how you setup your application code logic and how you have chosen to parse your code blocks!


me!

Link to comment
Share on other sites

printf

i am not sure how i want to do this as i have never created a template parser. my only foray into templates so far has been designing for wordpress sites.

i will definatly take your info on board and research yoru suggestions.

i did look at smarty, but from what i gather it needs to be installed on the server that the application will be on, and as this script will be made available for people to download at some point i cannot guarantee people will have smarty. maybe my understanding is wrong.

thanks for the information
Link to comment
Share on other sites

You can go to different open source developer forums and research this. I myself don't have a problem with Smarty, I just would never use it, also as [b]thorpe[/b] said, it is big, and I say, really bloated. I myself when teaching at different workshops have been asked about templating engines many times, still to this day, I would not recommend one, so in this case reinventing the wheel is a good idea, if you choose not to let PHP do what it does very well. One the most simplest explanation of why template engines are bad was written by Richard Heyes, a very nice chap that has been helping develop core parts of PHP for years, the article is short and sweet, but it get right to the point, [u][url=http://www.phpguru.org/static/templating.html]Templating, the correct way[/url][/u]!

Also, I don't think your understanding is wrong, because your asking your self what is the best way, and that most times means your trying to come up with the best logic, which any good developer should do! Just research it some more and try different things, but remember this, when it's templating your dealing with, less is more, in other words don't over complicate it!

me!
Link to comment
Share on other sites

i had a really good read of that link you sent and all the comments.

ok, so in my understanding now I am going to use plain php to serve up templates. the problems i have in doing this is that to do so would mean to provide a css sheet that the user can modify but NOT chnage the div id's and classes but only the settings of each one respectivley.

now i have used a php style switcher before to set a cookie so i know i can do that.

obviously i would like my users to design a template of there own creating there own html and css. would it be a good idea to convert all my php code that pulls the data from the db into functions. so i can write a small list of functions in a tutorial and just say "design how you like and use these fucnctions for the data"

because of my limited knowledge int hsi area maybe i have things wrong or i am asking the wrong questions. i apologise if any of this seems mundane or stupid. all your help has been appreciated and is definatly helping me

thank you
Link to comment
Share on other sites

  • 2 weeks later...
apologies for the late reply, its been a really long week.

people will be able to use this without having any log in details and they will have the coice of chossing which theme they want to view, so maybe the batabase idea would not work well for this.

my htinking is to have a THEME directory and each theme in its own folder. the main index will call the files depending on the choice of theme. for those who have used word press you will know what i mean. im still having some trouble figuring it out, but i have no touched it much this week as i have been away.

i am working on it this weekend though.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.