Welcome Guest, Not a member yet? Register   Sign In
An auto-templating idea
#1

[eluser]ntheorist[/eluser]
so I'm at the templating stage of building a cms, I've already employed the Template library (so stuff below might not make sense without it), and i was thinking it would be cool if my controllers would load their own templates automatically. (kinda like cake's automagic i guess?)

Maybe i'm lazy, but i didn't want to have to load all the redundant regions and templates and call render() in every single method of my controllers - it clutters up the important code that gets the data. Plus if i ever want to change template libraries or extend them i might have a slew of functions to find and change. So i'm working on a simple controller extension, and a (not so simple) library that would do this, and basically i'm mapping 'controller/method' to 'template/page', where page is actually an instance of the template.

I'm thinking there are a few pros to this:

1) you can control how every page in your site is processed from one controller
2) you're not breaking the CI standard, everything is still controller/method based, plus you can always extend the main Controller class, and i haven't checked yet but custom URI routes should still work.
3) you can have static pages with NO method needed to be defined for it (although they will not be dynamic besides any processing with the view itself) - this cleans up your contoller code, which then can be left to handle pages with data crunching
4) This could work with multiple sites or deep controllers, which could call up its own template map set.

The controller class itself is pretty simple too, using the _remap() function and changing just one line (non-destructively) of code in Router.php

it does require additional configuration, but in there you can specify all your overrides over the default template, or replace it altogether

the config would follow as such $pages['controller_name']['method_name'], and would assume you have your templates themselves and regions defined in their own config already. You could also have a page override the template with $pages['controller_name']['method_name']['template'] = 'page_template', and the regions inherited or overloaded by $pages['controller_name']['method_name']['regions']['region_name'] = 'view_to_load' etc..

Still a work in progress but shows potential i think for approaching the template methodology.

anyone second this idea or know of any pitfalls of going this direction? The next step would to be able to create the $pages config through a cms etc (site building), or bypass it altogether, pull the config from a db and store in the session (for multiple uses, ie navigations etc)

thx,

CC




Theme © iAndrew 2016 - Forum software by © MyBB