Yii Framework Forum: Does the theme feature in Yii support for components/views ? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Does the theme feature in Yii support for components/views ? Rate Topic: -----

#1 User is offline   revo110 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 78
  • Joined: 04-March 09

Posted 16 June 2009 - 08:56 AM

Hello,

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

#2 User is offline   revo110 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 78
  • Joined: 04-March 09

Posted 17 June 2009 - 03:59 AM

I guess we can't do that ?
0

#3 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,892
  • Joined: 04-October 08
  • Location:DC, USA

Posted 17 June 2009 - 09:11 AM

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.
0

#4 User is offline   revo110 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 78
  • Joined: 04-March 09

Posted 17 June 2009 - 06:15 PM

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!
0

#5 User is offline   mindplay 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 397
  • Joined: 03-September 09
  • Location:New York

Posted 03 January 2010 - 08:47 PM

View Postqiang, on 17 June 2009 - 09:11 AM, said:

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.


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 :-)
0

#6 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 03 January 2010 - 09:42 PM

View Postmindplay, on 03 January 2010 - 08:47 PM, said:

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 :-)



There is skinning available for widgets
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
0

#7 User is offline   Mike (UK) 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 01-August 10
  • Location:Exeter, UK

Posted 01 September 2011 - 06:22 AM

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.
0

#8 User is offline   vzangloo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 02-December 11

Posted 25 February 2012 - 12:36 PM

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!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users