Welcome Guest, Not a member yet? Register   Sign In
How to implement a theming/templating system?
#1

[eluser]RyanStubbs[/eluser]
Hey.

I'm working on a CMS script using CodeIgniter and I'm pretty new to this so I was wondering if anybody could help me with finding information about implementing a templating system in my application.

I would like a way to allow designers to easily create themes for my CMS without the end-user having to manually edit the files to allow for the design to work.

I would also like to allow dynamic content such as page titles and widgets to be easily inserted in different parts of the theme.

Please could someone help me by providing information about how to do this please?

Thanks a lot!

Ryan.
#2

[eluser]stuffradio[/eluser]
Put a folder in your views for themes, have a database table for themes (or maybe use your config table?). If you use a config table, you can store a global theme in it. Make the name of the theme the same name of the folder as your theme you want to use. Have your controller load that theme by getting the value of the global theme (or if they're logged in they can use the name of the theme that is stored in their user row).

That's pretty much all there is to it, theory wise. Try playing with that idea and come back if you have more questions, some people might have other theories they can offer too.
#3

[eluser]Snoob[/eluser]
You can use the SESSION to store the template folder. And a form to choose the template, when submit the form, It will change the SESSION
#4

[eluser]xwero[/eluser]
themes can be done by exposing the css styles in a user friendly way.

shuffling around the content of the page is trickier because there will always be a widget short because the developers haven't foreseen where people want to display certain information.

Snoob sessions are the worst when you want to theme a site. A session by default is not persistent. If someone choses a theme he/she wants the see the theme if they return to the site. But i don't think this is a front end discussion.
#5

[eluser]Thorpe Obazee[/eluser]
I've always used helpers when I create sites for theming. One helper for showing the categories, one for showing the pages, one for showing another thing.

The CSS files work on the markup produced by the helpers and you've got a new theme.
#6

[eluser]Eric Barnes[/eluser]
My method is to create a copy of Loader.php and place it in app/library/.

Next I change the view path to templates: $this->_ci_view_path = 'templates/';

Then I edit index.php and add the root as a php include path:
define('SITEPATH', realpath(dirname(__FILE__) . '/'));
set_include_path(SITEPATH . PATH_SEPARATOR . get_include_path());

Finally I create a new "templates" directory in the site root. Now everything is loaded from here and to me it makes it easier for folks to find the templates to edit. I also use one "layout.php" file which is a wrapper with the body included.
#7

[eluser]MEM[/eluser]
Suzkaw, that seems to be a very nice thing to do.
Because, by using that method, we don't need to change the core of the CI loader class.

One question however: Where do you have the other views that are not templates? And where are your header.php and footer.php files, supposing you having them?


Thanks a lot,
Márcio
#8

[eluser]Eric Barnes[/eluser]
Maybe seeing the files will help you better understand how I do it:

Loader Sub Class:
http://code.google.com/p/68kb/source/bro...Loader.php

Init Model - Used to display the templates:
http://code.google.com/p/68kb/source/bro..._model.php

Layout Template file:
http://code.google.com/p/68kb/source/bro...layout.php

Notice it calls <?php echo $body; ?> for the content.

If you want a header and footer you could do that from the init_model.
#9

[eluser]MEM[/eluser]
No more then 20 days on CI And I never wrote a complete OOP site on my life, so...
Sad(((( Sorry. To hard to understand.

I was thinking more of something like this:

in views folder file named “template.php”
$this->load->view('_header');
$this->load->view('_left');
$this->load->view($main);
$this->load->view('_footer');

and in controller
$data['title'] = "my title";
$this->load->vars($data);
$this->load->view('template');

But the issue here is that, I'm unable to separate the views folder on a decent way, so that I can have the templates and the views folder on a public folder, and the applications and system folder on a private folder like this:

Quote:/private
/application
/system

/public
/www
/assets
/views
/templates
.index.php

Should I give up on this, and just put them all on the public side... ?
#10

[eluser]Jondolar[/eluser]
You can create subdirectories for each "skin" under your /views directory and then load them like this:

$skindir = 'template1'; // assign this from a cookie, session, database, whatever
$this->load->view($skindir.‘/_header’);

Then, just create a directory called /views/template1 (and more for each template).

Good luck with your project.




Theme © iAndrew 2016 - Forum software by © MyBB