Jump to content


Photo

functions and templating


  • Please log in to reply
7 replies to this topic

#1 soddengecko

soddengecko
  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts

Posted 04 October 2006 - 11:46 AM

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?

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 October 2006 - 12:02 PM

Find yourself a decent template engine and learn how to use it. There all a little different. Smarty is one of the big ones, and I mean BIG. Personally I don't bother with them, but hey...

#3 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 04 October 2006 - 12:21 PM

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!



#4 soddengecko

soddengecko
  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts

Posted 04 October 2006 - 06:29 PM

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

#5 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 04 October 2006 - 07:03 PM

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 thorpe 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, Templating, the correct way!

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!

#6 soddengecko

soddengecko
  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts

Posted 05 October 2006 - 06:38 PM

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

#7 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 05 October 2006 - 07:04 PM

what it sounds like you need to do is just to add a new field to the user table with the user's respective CSS and just have it echoed out on their page.

when they register just have your query insert the default CSS
fuck it or fight it

#8 soddengecko

soddengecko
  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts

Posted 14 October 2006 - 02:48 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users