EllisLab text mark
Advanced Search
     
Theming support in CI - Dirty Hack
Posted: 01 October 2012 05:22 AM   [ Ignore ]
Joined: 2012-04-30
10 posts

Theming - Dirty Hack


Hi All,


I want to share with you about my Dirty Hack for theming support in CI.

It is simple and working just fine - I like simple things grin

Here is my folder structure:

/application/controllers/main.php
/application/views/main_view.php

/static/themes/default/
———————————mobile/
——————————————-js/
——————————————-css/
——————————————-images/
——————————————-views/
—————————————————-main_view.php

———————————ie/
————————————js/
————————————css/
————————————images/
————————————views/
——————————————-main_view.php

———————————html5/
—————————————-js/
—————————————-css/
—————————————-images/
—————————————-views/
————————————————main_view.php

/static/themes/custom/
———————————mobile/
——————————————-js/
——————————————-css/
——————————————-images/
——————————————-views/
—————————————————-main_view.php

———————————ie/
————————————js/
————————————css/
————————————images/
————————————views/
——————————————-main_view.php

———————————html5/
—————————————-js/
—————————————-css/
—————————————-images/
—————————————-views/
————————————————main_view.php


Where is HACK ?

Into:
/application/views/main_view.php (access url: http://localhost/main)

Include:

include_once "./static/themes/".$theme."/".$agent."/views/main_view.php" 

$theme:  default, custom
$agent:  mobile, ie, html5

$theme & $agent are passed from controller where I do check for user’s theme and for used agent (mobile, internet explorer and all others html5 compatible).

So all the time “Main” controller will call /application/views/main_view.php view.
Depend on theme users settings and agent used - appropriate View will be loaded from “themes” extended location (/static/themes/).


Additionally restrict access to VIEW folders inside of THEMES for security reason.
I use NGINX so here is syntax:

location /var/www/html/project_name/static/themes/default/html5/views {
deny all;
}
location /var/www/html/project_name/static/themes/default/mobile/views {
deny all;
}
location /var/www/html/project_name/static/themes/default/ie/views {
deny all;
}
location /var/www/html/project_name/static/themes/custom/html5/views {
deny all;
}
location /var/www/html/project_name/static/themes/custom/mobile/views {
deny all;
}
location /var/www/html/project_name/static/themes/custom/ie/views {
deny all;
}


I you use Apache, .htaccess will do job.


What do you think about this approach ?

Cheers !!!!