Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to change path to views?
  • I am building a cms which will have a themes/ folder in the root directory. It will contain the theme's view files and assets. How can I change the views path so that a theme's view doesn't have to be in a view/ folder. Here is an example tree: index.php
    themes/
    |-site_themes/
    |-|-some_theme/
    |-|-|-css/
    |-|-|-img/
    |-|-|-js/
    |-|-|-home.mustache
    |-|-|-two_col.mustache
    |-|-|-three_col.mustache
    |-|-another_theme/
    |-|-|-css/
    |-|-|-img/
    |-|-|-js/
    |-|-|-home.php
    |-|-|-about.php
    |-|-|-contact.php
    |-admin_themes/ So in the frontend controller... // I'm paraphrasing but in a nutshell...
    // add the theme's path and return a the theme's view
    \Fuel::add_path(DOCROOT . $current_theme, true);
    return Response::forge( View::forge('home') ); This, of course, expects the view to be in DOCROOT.$current_theme.'/views/'. Any and all ideas are welcomed. Thanks!
  • First, in your case, shouldn't:
    \Fuel::add_path(DOCROOT . $current_theme, true);
    

    be:
    \Fuel::add_path(DOCROOT . 'themes' . DS . $current_theme, true);
    

    ? Anyway, I don't know if there is a way to add your path without the views directory, but what you can do is extend the core. In /core/class/view.php on line 387 (1.1/develop) you see:
    if (($path = \Fuel::find_file('views', $file, '.'.$this->extension, false, false)) === false)
    

    If you'd extend this class and add this function in that class and modify the 'views' to whatever you want, it should work (and off course add the path DOCROOT). But why do you want your views in the public folder anyway?
  • Look into using the Themes class, it allows for an external theme folder with assets
  • You still can use a full absolute path to create the view:
    $view = View::forge(APPPATH.'themes'.DS.$your_theme.DS..'yourview.mustache');
    

    That way, you can put it wherever you want.
  • Awesome! I'll give this a try.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion