Does the theme feature in Yii support for components/views ?

Hello,

Can I put my components' view in the theme folder ? How can I do that ? I've tried but it didnt know…

I guess we can't do that ?

This is not supported currently. We have concern of performance because it means for every widget, when rendering a view, it would need to search under theme folder first.

If you are interested, you may give it a try by extending CWidget's render() method. You can refer to CControl on how it implements theme-based view rendering.

Quote

This is not supported currently. We have concern of performance because it means for every widget, when rendering a view, it would need to search under theme folder first.

If you are interested, you may give it a try by extending CWidget's render() method. You can refer to CControl on how it implements theme-based view rendering.

Hi qiang, thanks a lot.

I see, well then if it's with the performance issue related. I'll have a look on this later when I am done with my deadlines. All I need right now is only to know if it is possible, and you have answered it. Thanks a lot!

Best!

Seems I ran my head against a wall.

I am creating a theme for blogdemo-extended, for my personal blog - and I discovered tonight that theming components in not possible. The new skins feature doesn’t solve my problems either.

Wouldn’t it be better to solve this performance problem (which already exists when theming views) for all intents and purposes, so this feature can be implemented without worrying about performance?

I would propose simply caching all theme paths, once resolved the first time, in a runtime file - e.g. one file per theme, containing a simple associative array with ‘path’ => ‘resolved path’.

With an option to turn off path-caching, this should be comfortable to work with, both on production servers and during development.

The side effect from adding this feature would be a small speed gain when using themes in general, which can’t be considered a bad thing :slight_smile:

There is skinning available for widgets

Hi

I had a site map componet. I wanted to put the view in my theme/views/layouts/ folder so what I did was in the site map componet was as follows:




class SiteMapComponent extends CPortlet

{

    protected function renderContent()

    {

    	$view = './../../../themes/'.Yii::app()->theme->name.'/views/layouts/_site_map';

        $this->render($view);

    }

}



This works because as the manual says: Relative views will be searched for under the currently active controller’s view path.So all you need to do is create a relative path that navigates back to the document root and then to your theme.

I modified Mike’s code to

class SiteMapComponent extends CPortlet

{

protected function renderContent()


{


    $view = 'webroot.themes.'.Yii::app()->theme->name.'.views.layouts._site_map';


    $this->render($view);


}

}

It works fine!