css and js in the right place
Permalink
I'm so close to get all my code 100% XHTML Strict-valid right now, the only problem I have is with my blocks that require extra .css and .js files, for example: the Gallery Block.
All the links to my .css-files etc are simply placed in the blocks view.php. This ends up with the CSS- and JS-links in the <body>-section and not the <head>-section as it should be (yeah .js-files belong in the end of <body> but the .css...).
My idea is to place some kinda
<?php $extrahead = "LINK TO CSS"; ?> in the view.php-file and then print out the $extrahead in header.php.
I've done this before without C5 but now I just don't seem to get it working.
Help would be appreciated :)
All the links to my .css-files etc are simply placed in the blocks view.php. This ends up with the CSS- and JS-links in the <body>-section and not the <head>-section as it should be (yeah .js-files belong in the end of <body> but the .css...).
My idea is to place some kinda
<?php $extrahead = "LINK TO CSS"; ?> in the view.php-file and then print out the $extrahead in header.php.
I've done this before without C5 but now I just don't seem to get it working.
Help would be appreciated :)
Of all the google results I got one piece of code working but that did only spit the code out twice - in the <body> :(
This 5.3 seems to have a couple other functions I'm waiting for, will it fix these problems too? :)
This 5.3 seems to have a couple other functions I'm waiting for, will it fix these problems too? :)
Goddamn I'm stupid. Fixed the problem,
added
"<?php
$this->outputHeaderItems();
?>"into <HEAD> in header.php
and added "$this->addHeaderItem('<stuff>');"
in the "function __construct($obj = null) {"-function at the controller.php.
Thank you so much :)
Now I've got to heat up the sauna again :(
added
"<?php
$this->outputHeaderItems();
?>"into <HEAD> in header.php
and added "$this->addHeaderItem('<stuff>');"
in the "function __construct($obj = null) {"-function at the controller.php.
Thank you so much :)
Now I've got to heat up the sauna again :(
outputHeader isn't necessary..
Oh yes... no it isn't.
In my custom theme the header_required.php is included only for logged on users so all the concrete stuff works...
This way I get a much cleaner output...
In my custom theme the header_required.php is included only for logged on users so all the concrete stuff works...
This way I get a much cleaner output...
<head> <title><?php echo $c->getCollectionName() . ' | ' . SITE ?></title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="/style/style.css" /> <?php $this->outputHeaderItems(); ?> <?php if(User::isLoggedIn()) { Loader::element('header_required'); } ?>
I see, makes sense..
Don't you get a "double-header" with your code? JavaScripts in the header twice?
Don't you get a "double-header" with your code? JavaScripts in the header twice?
and i hate you for having a sauna. ;)
This is unsatisfactory. Not enough freedom. Use of addHeaderItem is confined to block controller code, or to situations where the code to be inserted into the head section is somehow related to a specific block. What I want is a [b]global[/b] function, or a method of the Concrete object, that could be used from [b]anywhere[/b] to just "throw" header content in the air, knowing that the framework will "catch" it and put it in the header section.
it's not really restricted to the block controller only..
Can you make some examples where you'd need to call it? I've built quite a lot of c5 stuff and never needed anything else.
This method can't be anywhere, at some point the framework must write the header, otherwise it would mess up with the output buffering but as I wrote above, give us some examples as I really don't see what you're looking for - thanks!
Can you make some examples where you'd need to call it? I've built quite a lot of c5 stuff and never needed anything else.
This method can't be anywhere, at some point the framework must write the header, otherwise it would mess up with the output buffering but as I wrote above, give us some examples as I really don't see what you're looking for - thanks!
Like Remo says, it's not just confined to the block on_page_view() functions within the block controller. You're also able to add it through the page controller at any point, since the page controller is also rendered before the header starts.
You can also use the global on_before_render event
http://www.concrete5.org/help/building_with_concrete5/developers/mv...
You can also use the global on_before_render event
http://www.concrete5.org/help/building_with_concrete5/developers/mv...
Following the discussion by:
http://www.concrete5.org/index.php?cID=11162...
The preceding discussion is the:
http://www.concrete5.org/index.php?cID=6233...
http://www.concrete5.org/index.php?cID=11162...
The preceding discussion is the:
http://www.concrete5.org/index.php?cID=6233...
If you would like to add extra CSS and JS to a block, simply create CSS and JS directories within the block and put them there. They are automagically added to the head of the page.
Use auto.js to call any functions within the JS, if using plugins etc.
Use auto.js to call any functions within the JS, if using plugins etc.
This is the method you can call within a block controller that lets you add stuff to the header...
There are a few cool features in 5.3 which will be available soon! I guess just a couple of days maximum