Welcome Guest, Not a member yet? Register   Sign In
Super easy template system
#2

[eluser]Rolly1971[/eluser]
i don't mean to be critical but there is a better way. By what i see each view partial needs it's own controller. Instead of that method:

to load common items create a MY_Controller class (and for CI1.7.2 save it under application/libraries. It will be auto magically loaded by CI, CI 2.0 save it under application/core) that extends Controller, then extend all your controllers from it instead. Use this Controller to load all your common items such as : header, footer, template. Then your controllers in application/controllers load the content required and then you can either send the content from your controllers to MY_Controller for merging into the template and perform the output or store the built template that MY_Controller creates inside a variable that the page controller can access and merge them in there.

The way i do it is like this sorta. I have a MY_Controller that loads all common view partials, the page controllers extend it, they also request data from the db through a class i made called: theme_model. This class loads content from the database. once the controller has all it's info it passes that to the MY_Controller which puts the final page to the browser.

CI comes with a template parser class. fairly basic in its implimentation, but also very easy to use and wrap a template library around.

check out Phil Stergeons template library. Or Colin Williams Template Library, i think they may work quite well for you they are very simplistic in their elegance.

If you prefer to do it yourself like me, they will at least give you some insite into creating a template class in CI.


Messages In This Thread
Super easy template system - by El Forum - 10-13-2010, 04:10 PM
Super easy template system - by El Forum - 10-13-2010, 08:47 PM
Super easy template system - by El Forum - 10-13-2010, 09:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB