Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
What is theme and themeinfo?
  • As I understand, theme is a view file (not folder) and themeinfo is a config file.

    Is themeinfo used one for all themes or one file per theme? If second (as I expect) then where does it have to be placed?

    I want something like this structure:
    themes
    themes/admin/
    themes/admin/default/
    themes/admin/default/template.php
    themes/admin/default/themeinfo.php

    themes/admin/black/
    themes/admin/black/template.php
    themes/admin/black/themeinfo.php

    themes/default
    themes/default/template.php
    htemes/default/themeinfo.php

    themes/silver
    themes/silver/template.php
    themes/silver/themeinfo.php

    Or another way:
    themes
    themes/admin
    themes/admin/default.php
    themes/admin/default.ini (instead of themeinfo.php)
    themes/admin/black.php
    themes/admin/black.ini
    themes/default.php
    themes/default.ini
    themes/silver.php
    themes/silver.ini

    How to? Any of this... Thanks.
  • HarroHarro
    Accepted Answer
    To start with your last question: themeinfo isn't used anywhere. It is meant to store theme specific config, either for the theme itself, or for theme installers.

    For example, say you have a theme that is available in 4 colours, then you could define those colours in the info file, so a theme installer controller could present them to the user for selection. The selected colour could then be written back to the theme knows in which colour it needs to be displayed.

    You have an info file per theme, in the root of the theme folder, and there is no cascading involved, it's a single file that gets loaded.

    And no, a theme is a folder, containing a collection of view files, which behaves exactly the same way as files in APPPATH/views.

    The biggest differences:
    • for views the root path is fixed (APPPATH/views), for themes it's the active theme root
    • themes have an active and a fallback with cascading
      you can use an active to override for example only a single css file and re-use everything else from the fallback.
    • themes have build-in support for page templates and partials
  • Thank you, Harro. I understand this.

    But what aboute "use_modules" option. It has something strange logic on my opinion to divide theme on modules instead of divide modules on themes.

    It's only my point of view, but I want better have this structure:

    theme/admin/<theme_name>
    theme/<another_module>/<theme_name>
    theme/<theme_name>

    nether this:

    theme/<theme_name>/admin
    theme/<theme_name>/<another_module>

    Because some modules can have separate themes, but not all themes must consist templates for all modules, as I see :)

    Now, I think how to turn this logic for my preference :)
  • HarroHarro
    Accepted Answer
    If you don't need it, don't use it. ;-)

    The "use_modules" config key does several things. If set to true, it will enable the use of themes folder inside the module folder structure.

    The use case behind it is: say you have an application that support theming as a feature. For example a CMS. And say you provide 10 themes for your CMS, and there are external parties that create themes to. Say also that your CMS has to option to install plugins that are written as Fuel modules.

    Now, how would you make such a module work after installation? None of the existing themes know this module, none of them have the correct views.

    When 'use_modules' is set to true,  it introduces a themes folder in a module, so the module can provide either theme specific views ("this module supports theme A, B and C") or views for a default theme, so at least there is something to display after you have installed the module.

    For an application where you control everything yourself, this functionality isn't really useful.

    The second use is to assign a string to the key 'use_modules'. This does two things:
    - it uses this string as a path prefix
    - it activates the module name prefix

    So, if it is set to true, and you load the view "index" from a "admin" module controller, it will load:
    - MODULES/admin/themes/<activetheme>/index
    - if not exist, THEMES/<activetheme>/admin/index
    - if not exist, THEMES/<activetheme>/index
    - if not exist, a standard view by the name "index"
    - "view not found"

    If it is set to the string "test", it will load:
    - THEMES/<activetheme>/test/admin/index
    - if not exist, THEMES/<activetheme>/test/index
    - if not exist, a standard view by the name "index"
    - "view not found"

    If it is set false, it will load:
    - THEMES/<activetheme>/index
    - if not exist, a standard view by the name "index"
    - "view not found"

  • >>So, if it is set to true, and you load the view "index" from a "admin" module controller, it will load:
    - MODULES/admin/themes/<activetheme>/index


    Oh, yes! This is good! I didn't find it before you say :-)

    But I have some troubles again... Ok, I will try resolve it or formulate a new question later :-)

    Thank you.
  • Is there any sample for "theme"?
  • Not that I know of. But it's just a collection of views and asset files.
  • Oh, I found a new question to ask :)

    When I set tempalte before change active theme, will template be changed appropriate?

    In base controller:

    $this->theme = \Theme::instance();
    $this->theme->set_template('index');

    Later in controller:

    public function before()
    {
            parent::before();
            $this->theme->active('silver');
    }

    It seems the theme/default/index.php loaded anyway... not theme/silver/index.php. Why?
  • Ok, question is not actual. I found nice decision of my problem ;-)

Howdy, Stranger!

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

In this Discussion