Welcome Guest, Not a member yet? Register   Sign In
using views from a themes folder
#1

[eluser]Michael;[/eluser]
Good morning folks,

I am currently working a project that has a three different applications running on the same site, so currently I have as follows:

-> /system
-> /default
-> /admin
-> /meddata
-> /public_html
-> -> /themes
-> -> /images
-> -> /js
-> -> index.php
-> -> admin.php
-> -> mdata.php

We have everything working so long as we put themes and all related view files in the views folder of each application, however, that means we are duplicating a lot of code at the moment as everything changes a bit from one theme to the next. Having 3 themes at the moment, and potentially more in the future, dictates that we should find a way to do this ASAP.

I've done a forum search and cannot figure out a way thus far to load views from outside the application folder. Has anyone else figured out a way to do this?

Thanks everyone.
#2

[eluser]adamp1[/eluser]
I don't think this is a feature currently in CI. Sounds like a custom library or core extension would be needed. Would be a nice thing to see though I can a lot of people would have use for such a thing.
#3

[eluser]bradym[/eluser]
When including a view, it looks by default in application/views, so assuming you have header.php in application/views, you'd just do:

Code:
$this->load->view('header');

You can also include the path when calling a view, so you should be able to do this:
Code:
$this->load->view('../../../public_html/themes/header.php');

You may want to set a constant to make it easier, since it sounds like you'll be doing this quite a few times. So put the following in index.php:

Code:
define('THEMEPATH','../../../public_html/themes/');

Then to load your views:

Code:
$this->load->view(THEMEPATH.'header.php');

Brady
#4

[eluser]esra[/eluser]
You can extend the Loader library (create a MY_Loader.php) and overload the view method to scan through additional directories. As far as CI is concerned, a view is a view regardless if it is a template, partial, or empty view fragment. CI looks for views in the application/views/ or in whatever application directory you specify in index.php. I posted some view method changes to load templates from application/templates/ and partials from application/blocks/. See if you can find the Modular Separation 2.4.1 thread. I believe the code was posted there. The code may be stale since it was for CI 1.5.4, but it should work with 1.6.x.




Theme © iAndrew 2016 - Forum software by © MyBB