Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP themed plugin view

Is it possible to theme a plugin's view? I have a mobile theme for mobile devices and would like to use different view files for a plugins app/views as well. I have tried app/views/themed/THEME/plugin/... and /app/plugins/PLUGIN/views/themed/THEME/...none seem to work. Thanks in advance.

like image 482
Michael Avatar asked Jan 17 '23 16:01

Michael


1 Answers

Copy content of your theme to: app/views/themed/THEMENAME/plugins/PLUGINNAME/ Create a ThemePluginsView class on app/libs/view/theme_plugins.php

// app/libs/view/theme_plugins.php
if (!class_exists('ThemeView'))
    App::import('Core', 'view/theme');

class ThemePluginsView extends ThemeView {

    function __construct(&$controller, $register = true) {
        parent::__construct($controller, $register);
    }

    function _paths($plugin = null, $cached = true) {
        $paths = parent::_paths($plugin, $cached);
        if (!is_string($plugin) || empty($plugin) || empty($this->theme))
            return $paths;
        // add app/plugins/PLUGIN/views/themed/THEME path 
        $dirPath = APP . 'plugins' . DS . $plugin . DS . 'views' . DS . 'themed' . DS . $this->theme . DS;
        if (is_dir($dirPath))
            $paths = array_merge(array($dirPath), $paths);
        return $paths;
    }
}

Then call it on your app_controller on beforeFilter() or usual controller on beforeFilter() like:

function beforeFilter() {
  if (!class_exists('ThemePluginsView'))
    App::import('Core', 'view/theme_plugins');
  $this->view = 'ThemePlugins';
  $this->theme = 'THEME_NAME';
}

Hope it helps

like image 89
Sudhir Bastakoti Avatar answered Jan 30 '23 12:01

Sudhir Bastakoti