css requiring

css requiring

by Rustam Gasanov -
Number of replies: 12

hello everyone, i'm constructing a filter that in some situations need to include a grids-min.css file (lib/yui/3.2.0/build/cssgrids/grids-min.css) in the current page. but when i'am trying to use

$PAGE->requires->css('lib/yui/3.2.0/build/cssgrids/grids-min.css');

i've got an error below

Coding error detected, it must be fixed by a programmer: Cannot require a CSS file after <head> has been printed.

Is there any other way to include this file to the page,  if not - maybe include this grids in every page.

ps: why require->js got a second argument (bool $inhead initialise in head) and the require->css don't have it?

thanks

Average of ratings: -
In reply to Rustam Gasanov

Re: css requiring

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Just make a styles.css file inside the filter folder, and that will be included on every page. (Make sure theme designer mode is switched on when you are developing this.) In Moodle 2.0, all CSS from all plugins is combined, minified and cached. It is then served to users with instrucutions to their browser to cache it for a long time. This is best for performance. Therefore, try not to do conditional includes of CSS.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: css requiring

by Rustam Gasanov -

Thanks for your reply, Tim. I have just created a simple styles.css file with .mydiv { color:red;} single line, move this file to the my filter folder, then edit the lesson by adding a "<div class="mydiv">some text</div>" and it seems that my file was not included because this text aren't red sad how can i enable theme designer mode? is it nessesary?

In reply to Tim Hunt

Re: css requiring

by Rustam Gasanov -

oh sorry, cache purging helps, thanks again!

In reply to Rustam Gasanov

Re: css requiring

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That was my comment about theme designer mode. Basically, you can either keep clicking purge caches, or you can turn off the caching completely.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: css requiring

by imketu p -

hello

i am getting same error

Coding error detected, it must be fixed by a programmer: Cannot require a CSS file after <head> has been printed.

but only for on one particular users profile page

any idea?

Thanks

 

In reply to imketu p

Re: css requiring

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Which page? Give us the URL.

And, turn Debugging to developer level to get a stack trace.

In reply to Tim Hunt

Re: css requiring

by imketu p -

Thanks for reply

url is http://xxxxxxxxxxxxxxxx/user/profile.php?id=8

More information about this error

Debug info: /blocks/accessibility/userstyles.php
Stack trace:
  • line 595 of \lib\outputrequirementslib.php: coding_exception thrown
  • line 66 of \blocks\accessibility\block_accessibility.php: call to page_requirements_manager->css()
  • line 280 of \blocks\moodleblock.class.php: call to block_accessibility->get_content()
  • line 232 of \blocks\moodleblock.class.php: call to block_base->formatted_contents()
  • line 926 of \lib\blocklib.php: call to block_base->get_content_for_output()
  • line 978 of \lib\blocklib.php: call to block_manager->create_block_contents()
  • line 311 of \lib\blocklib.php: call to block_manager->ensure_content_created()
  • line 957 of \lib\outputrenderers.php: call to block_manager->get_content_for_region()
  • line 353 of \user\profile.php: call to core_renderer->blocks_for_region()

Thanks

Average of ratings: Useful (1)
In reply to imketu p

Re: css requiring

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi imketu,

It appears that you're using my Accessibility block, which is causing the problem.  However, I've never come across this problem myself.  What version of Moodle are you using?

Thanks
Mark

In reply to Mark Johnson

Re: css requiring

by imketu p -

i am using moodle 2.2

and the problems is only for one user while checking user profile.

on same link for other users profile is ok.

is it possible that user has done some settings in accessibility block and save his own settings? i have uninstall accessibility block and  re-installed again.

 

Thanks

 

In reply to imketu p

Re: css requiring

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi imketu,

I think this is an issue with the accessibility block itself, it has to include an extra stylesheet to apply the user's personal modifications, but  this is being done after the page's header has already been output.  At a guess I'd say that the block is being displayed in the middle of the page, is this the case?  Blocks in the left and right columns will be output by $OUTPUT->header(), but (at least on user/profile.php) the middle region is displayed by a seperate $OUTPUT->blocks_for_region() afterwards.

If that's what's happening, I'll need to try modifying the way the block includes the per-user CSS to take this case into account.