Yii Framework Forum: Can't Get The Theme Css To Work - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Can't Get The Theme Css To Work Rate Topic: -----

#1 User is offline   sercio 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 05-November 13

Posted 06 November 2013 - 02:55 AM

Hello Everybody,

I'm new to the Yii Framework (all web development subjects for that matter) and I'm working through the Packt Publishing's Beginning Yii.

My directory structre is something like:
/protected
/runtime
/www
All has been defined accordingly in main.php based on the course video and site is working just fine.

Through the course, there is a task regarding themes to be accomplished. Instructions are simple enough:

1. copy the www folder from the course package to the related folder (in my case, /webroot/www/themes
themes folder includes:

classic
../views
../../layouts
../../site
../../system
photoGal
../css
../../screen.css
../images
../../bg.png
../views
../../layouts
../../site
../../system


2. define the layout name in the protected/config/main.php

I have done as I asked, but theme did not seemed to work at all. I decided to tinker with the theme provided CSS a bit, but it does not seem to take any effect on the rendered webpage. I decided to go deep and I found the www/main.css file. When I change this, it does take effect. But when I change the www/themes/photoGal/css/screen.css file, it has no effect at all.

When I try to output <?php echo Yii::app()->theme->name ?> on a view, it prints out photoGal, so I think it is not related to the configuration.

Any ideas?
0

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 06 November 2013 - 03:26 AM

Make sure the path to screen.css in a layout is:

Yii::app()->theme->baseUrl.'/css/screen.css'

0

#3 User is offline   sercio 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 05-November 13

Posted 06 November 2013 - 04:21 AM

View Postandy_s, on 06 November 2013 - 03:26 AM, said:

Make sure the path to screen.css in a layout is:

Yii::app()->theme->baseUrl.'/css/screen.css'



Hi Andy, thanks for your response.
I just inserted an echo statement for ->theme->baseUrl to one of my pages, it outputs:

/themes/photoGal

and path to my screen css is:
/themes/photoGal/css/screen.css

It seems ok, but still no luck.
0

#4 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 06 November 2013 - 04:45 AM

Check page source code. Is /themes/photoGal/css/screen.css being loaded in head section? If styles don't apply, then I guess not...
0

#5 User is offline   sercio 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 05-November 13

Posted 06 November 2013 - 05:05 AM

View Postandy_s, on 06 November 2013 - 04:45 AM, said:

Check page source code. Is /themes/photoGal/css/screen.css being loaded in head section? If styles don't apply, then I guess not...


It seems it loads css files from /css folder only (/css/screen.css, /css,print.css etc). /themes/photoGal is not present in the source whatsoever.

By the way, relevant section of my config file (main.php) is as follows:

function _joinPath($dir1, $dir2) {
    return realpath($dir1 .'/' . $dir2);
}

$homePath       = dirname (__FILE__). '/../..';
$protectedPath  = _joinPath($homePath, 'protected');
$webrootPath    = _joinPath($homePath, 'www');
$runtimePath    = _joinPath($homePath, 'runtime');


return array(
	'basePath'      => $protectedPath,
        'runtimePath'   => $runtimePath,
	'name'=>'Photo Gallery',
        'theme'=> 'photoGal',

	// preloading 'log' component
	'preload'=>array('log'),

0

#6 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 06 November 2013 - 11:49 AM

So your layout looks like:

<!DOCTYPE html>
<html lang="ru">
<head>
    ...
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->baseUrl; ?>/css/main.css" />
    ...
</head>
...


? But it should be Yii::app()->theme->baseUrl instead.
1

#7 User is offline   sercio 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 05-November 13

Posted 07 November 2013 - 02:07 AM

View Postandy_s, on 06 November 2013 - 11:49 AM, said:

So your layout looks like:

<!DOCTYPE html>
<html lang="ru">
<head>
    ...
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->baseUrl; ?>/css/main.css" />
    ...
</head>
...


? But it should be Yii::app()->theme->baseUrl instead.


Oh, silly me. I somehow figured that Yii will automatically look to the themes folder for css files even without a layout file in it. I don't know where did I get that idea. I copied the layout files to the theme folder and modified as you described, now it works like a charm. Thank you very very much!
0

#8 User is offline   Benn 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 16-January 11
  • Location:Paris

Posted 26 November 2013 - 05:08 AM

Hello,

this actually did not work for me. It did indeed apply the screen.css style from the theme, but all the information from the original screen.css was, as can be excpected not applied so I did not get the same result as in the video. The solution I found was to leave the original reference to the main screen.css and add a line for the theme's screen.css

<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/screen.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->theme->baseUrl; ?>/css/screen.css" media="screen, projection" />
	


How come the author of the videos gets things working fine without all this though?

Cheers
0

#9 User is offline   Chris Backhouse 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 04-August 11
  • Location:France

Posted 30 December 2013 - 08:10 AM

View PostBenn, on 26 November 2013 - 05:08 AM, said:


<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/screen.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->theme->baseUrl; ?>/css/screen.css" media="screen, projection" />


How come the author of the videos gets things working fine without all this though?

Cheers


Hello

The theme should have a layout file, and in my Dev version it is present, but somehow it is not in the Section 2 zip files.

You can find the correct version in the Section 3 zip file, so copy the theme directory from the Section 3 zip into your www directory.
0

#10 User is offline   aolee 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 20-April 14

Posted 20 April 2014 - 07:06 AM

Hi Chris,

There's also no layout file in Section 3 Zip file, i found one in Section 4. Hope this helps others who also purchased the video :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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