Page 1 of 1

Override module themes?

PostPosted: 24 Mar 2013, 00:14
by oaao
Trying to override

protected/modules/quicksearch/views/index.php

in

themes/my-site/..../index.php

but no combination of directories seems to work. Any idea why?

This should be possible based on http://www.yiiframework.com/doc/guide/1 ... cs.theming

on a related note, it might be a good idea to move all views out of module folders and into themes/default/.../ so they're easier to override without altering core files.

Re: Override module themes?

PostPosted: 24 Mar 2013, 08:44
by Xpycm
In protected\components\Module.php file try comment/delete the line:
Code: Select all
$this->setViewPath(Yii::app()->getBasePath() . '/modules/' . $this->getName(). '/views'); 

Re: Override module themes?

PostPosted: 24 Mar 2013, 19:40
by oaao
Thanks, but didn't seem to change anything for me. Where would the theme version of modules/quicksearch/index go?

Re: Override module themes?

PostPosted: 25 Mar 2013, 08:32
by Xpycm
oaao wrote:Thanks, but didn't seem to change anything for me.


It seems strange ...
Are you sure that you have pressed F5 after changes? :-)

oaao wrote:Where would the theme version of modules/quicksearch/index go?


protected\modules\quicksearch\views\index.php file and protected\modules\apartments\views\widgetApartments_list.php file

See more about design - viewtopic.php?f=17&t=326#p1563

Re: Override module themes?

PostPosted: 25 Mar 2013, 16:15
by oaao
I'm using a theme by placing this in config/main.php:

Code: Select all

$config 
= array(
    
'theme'=>'mysite',
 


which causes Yii to check

Code: Select all

themes
/mysite/...
 


for most layout. The new version of Yii should be able to override modules and widgets inside your own theme directory, for example, something like:

Code: Select all

themes
/mysite/views/quicksearch/index.php
themes
/mysite/views/apartments/widgetApartments_list.php


but nothing I've tried works. Any idea where these files would be under themes?

Re: Override module themes?

PostPosted: 28 Mar 2013, 09:46
by Koduc
We made some changes in structure of applications and themes are not supported by default at this moment.
You can try to make following changes to resolve it:
Open file /protected/components/ModuleUserController.php and add function:
Code: Select all
    public function getViewFile($viewName){
        if((
$theme=Yii::app()->getTheme())!==null && ($viewFile=$theme->getViewFile($this,$viewName))!==false)
            return 
$viewFile;
        
$moduleViewPath=$basePath=Yii::app()->getViewPath();
        if((
$module=$this->getModule())!==null)
            
$moduleViewPath=$module->getViewPath();



        
$theme Yii::app()->theme;
        if(
$theme && $theme->name){
            
$themePath $theme->getViewPath().DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR.$this->getModule($this->id)->getName();
            if(
is_file($themePath.DIRECTORY_SEPARATOR.$viewName.'.php')){
                
$moduleViewPath $themePath;
            }
        }
        return 
$this->resolveViewFile($viewName,$moduleViewPath,$basePath,$moduleViewPath);
    } 

After that, files for theme has following paths:
/themes/<theme name>/views/layouts (original path: /protected/views/layouts)
/themes/<theme name>/views/modules/<module name>/ (original path: /protected/modules/<module name>/views)
/themes/<theme name>/views/site/ (original path: /protected/views/site)