Welcome Guest, Not a member yet? Register   Sign In
Trying to create a good template system but need help
#1

[eluser]gunnarflax[/eluser]
Hi everybody! I'm trying to create a good template system for my cms. What I want to achieve is a folder structure like this:

Code:
- admin (backend)
- site (frontend)
- system

The admin and site folders are copies of the default application folder and since I want to be able to easily update CI I don't want to create any special folders within the application or meddling with the system files.

What I got now is all view files within the views folder but I want to have subdirectories here so that I can have different themes for the application. The problem is that I want to be able to keep all theme-related files in here so that I have images, css and js here as well and can easily include them into the view without having to specify the themes folder name - so that it would act as the view files are relative to the views folder, not like this: "theme_name/header.php". I don't know how I shall do with images and css as it is right now.

Basically what I want is to be able to use themes as in Wordpress.

Has anyone done anything similar?
#2

[eluser]InsiteFX[/eluser]
When updating CI you do not need to replace the application folder only the system folder!
Unless it's a major update that modifies the application folder.

application
-- themes
---- admin
---- site
---- default

application
-- views
---- admin
---- site

InsiteFX
#3

[eluser]gunnarflax[/eluser]
Ok, thanks, but that doesn't answer my main question. Has anyone or do anyone have any information on how to best implement a theming system for applications built with CodeIgniter?
#4

[eluser]gunnarflax[/eluser]
On second thought that is exactly what I wanted! Thanks InsiteFX! In my views folder I've put two folders called "backend" and "frontend" and use a class I called Template which allows me to use paths relative to the template when linking content.

Thanks!
#5

[eluser]Amitabh Roy[/eluser]
I general have a directory called assets which is in the same level as the system directory.
Inside the assets I put the css, js, images directories.

For one project I needed to have multiple themes , so I had a theme directory inside the assets directory. The theme directory contained multiple themes(directories), each of which is a directory containing the css and images in separate folders. The css name is the same in all the themes , so the theme directories have the structure

assets/themes/blue_theme/style.css
assets/themes/blue_theme/images/

assets/themes/yellow_theme/style.css
assets/themes/yellow_theme/images/

assets/themes/green_theme/style.css
assets/themes/green_theme/images/

Now to be able to refer to the theme directory, I create a custom config file and put the path to the themes folder as a config entry.

Code:
$config['themes_dir'] = 'http://localhost/mycodeignitersite/assets/themes/';

I also store the themes entries in a separate theme table so that users can choose the theme.
So for a given user who has chosen a green theme, the css is generated as follows


Code:
//lets say $userTheme is the selected user theme
<link href="<?php echo $this->config->item('themes_dir').$userTheme.'/style.css';?>" rel="stylesheet" type="text/css" />

Of course this approach is applicable for only css based themes where the html structure/layout of the page doesn't vary much. For themes which will use a complete different set of layouts(which means different views) a similar approach can be taken.
#6

[eluser]gunnarflax[/eluser]
That's another good idea, but I will stick to my solution for now because it allows me to have html and assets in whichever structure I like.

Code:
// To insert a link tag with absolute path I do:
echo link_tag($tpl->path('style.css', TRUE));
// (TRUE is a variable which makes it an absolute URL)

// To load a view within a view I use:
$tpl->fetch('footer.php');
// Which is simply a function which retrieves that correct
// path relative from the views dir and loads the selected view

// And to load from a sub-dir I just:
$tpl->fetch('pages/home');




Theme © iAndrew 2016 - Forum software by © MyBB