functions and templating
Posted 04 October 2006 - 11:46 AM
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?
Posted 04 October 2006 - 12:02 PM
Posted 04 October 2006 - 12:21 PM
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!
Posted 04 October 2006 - 06:29 PM
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
Posted 04 October 2006 - 07:03 PM
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!
Posted 05 October 2006 - 06:38 PM
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
Posted 05 October 2006 - 07:04 PM
when they register just have your query insert the default CSS
Posted 14 October 2006 - 02:48 PM
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