This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

davidmassianirennes347
davidmassianirennes347

I try to make a component who use layout from theme.

    $this->theme =  Theme::getActiveTheme();
    $this->assetPath = $this->themeUrl(); // return 'themes/demo'

    $partialPath = $this->getViewPath($partial, $this->assetPath .'/layouts/section');

and I have a exception The partial '/themes/demo/layouts/section/_test.htm' is not found.

How can I get root path of theme ?

Daniel81
Daniel81

Try '[path]/themes/'.Config::get("cms.activeTheme",'').'/layouts/'

davidmassianirennes347
davidmassianirennes347

The partial '[path]/themes/demo/layouts/section/_test.htm' is not found. [path] is undefined or I need to use classe ?

Daniel81
Daniel81

@davidmassianirennes347

The [path] was just a holder, ignore it, was just incase you need to go up a few directories like ../../themes/ etc.

If the above is placed in the acme/plugin/components/Component.php file, this path will work "themes/".Config::get("cms.activeTheme",'')."/layouts/_test.htm". Just remember to use Config;.

Last updated

davidmassianirennes347
davidmassianirennes347

Works perfectly. Thanks !

KurtJensen
KurtJensen

Might want to use PHP constant DIRECTORY_SEPARATOR instead of "/" for M$ server compatability.

Example:

define('DS',DIRECTORY_SEPARATOR);
$this->page['test'] = "themes".DS.Config::get("cms.activeTheme",'').DS."layouts".DS."_test.htm";

Last updated

jreis
jreis

I run across this old post, after searching for a similar problem. The answers here, aren't entirely right.

Config::get("cms.activeTheme",'') 

Will return the active theme on config/cms.php. Witch my not be the active theme (eg.: if the active theme is set on the backend ).

To get the "real" active theme, should be something like this.

$theme =  Theme::getActiveTheme();
$path = Config::get('cms.themesPath', '/themes').'/'.$theme->getDirName();

more info in:

  • modules/cms/classes/Theme.php
  • modules/cms/classes/Controller.php
andrepo18380
andrepo18380

Hi folks,

I was trying to do something similar but since the suggested solution looks at the config this doesn't quite work the frontend theme is changed on the backend.

I think @davidmassianirennes347 was in the right track ...

Here's how I've done to make sure we are getting the current active theme path:

use Cms\Classes\Theme;
$theme = Theme::getActiveTheme();
$theme_path = $theme->getPath();

Hope this is useful for someone in the future.

Cheers!

1-8 of 8

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.