Override module themes?

Questions and answers about change of functions, design, hosting etc.

Moderators: Koduc, Xpycm

Forum rules
Pay attention! Forum is not a means for guaranteed support of clients and users. An answer as well as a quick answer is not supposed on the forum. We post messages as soon as possible.

The message limit on the forum is 3 messages per day.
If you want to say "thank you" then use the function "Give good reputation point", which is a green icon "plus" under the nickname of the person, who answered the message.

Override module themes?

Postby oaao » 24 Mar 2013, 00:14

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.
oaao
Stranger
 
Posts: 14
Joined: 24 Mar 2013, 00:08
Reputation point: 0

Re: Override module themes?

Postby Xpycm » 24 Mar 2013, 08:44

In protected\components\Module.php file try comment/delete the line:
Code: Select all
$this->setViewPath(Yii::app()->getBasePath() . '/modules/' . $this->getName(). '/views'); 
Dropbox
Open Real Estate CMS: FAQ | FAQ 2 | FAQ 3
Image
Xpycm
Web Developer
Web Developer
 
Posts: 281
Joined: 30 Dec 2011, 11:06
Reputation point: 2

Re: Override module themes?

Postby oaao » 24 Mar 2013, 19:40

Thanks, but didn't seem to change anything for me. Where would the theme version of modules/quicksearch/index go?
oaao
Stranger
 
Posts: 14
Joined: 24 Mar 2013, 00:08
Reputation point: 0

Re: Override module themes?

Postby Xpycm » 25 Mar 2013, 08:32

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
Dropbox
Open Real Estate CMS: FAQ | FAQ 2 | FAQ 3
Image
Xpycm
Web Developer
Web Developer
 
Posts: 281
Joined: 30 Dec 2011, 11:06
Reputation point: 2

Re: Override module themes?

Postby oaao » 25 Mar 2013, 16:15

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?
oaao
Stranger
 
Posts: 14
Joined: 24 Mar 2013, 00:08
Reputation point: 0

Re: Override module themes?

Postby Koduc » 28 Mar 2013, 09:46

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)
-- Меньше знаешь - крепче спишь --
User avatar
Koduc
Team lead
Team lead
 
Posts: 64
Joined: 28 Dec 2011, 09:11
Reputation point: 0


Return to Questions and help for changes

Who is online

Users browsing this forum: No registered users and 5 guests

cron