What is the C5 best practice way of adding an external CSS file to view.php?
Permalink
Presently in my blocks I simply create an external CSS file and call it view.css (for no reason other than I want it to be clearly associated with view.php in my mind).
I then include that css file as usual at the top of my view.php file like so...
It works but I am wondering if there is some other way that I should be doing this?
For example I recently found out that adding Javascript at the top of my view.php file manually inside SCRIPT elements wasn't the preferred way to do that. Just wondering if maybe there is something similar with respect to external CSS files respecting a best practices way of doing things that does not involve putting the code above at the top of my view.php file.
I tried creating a CSS sub-directory off the block root to see if C5 might pull that in automatically like it pulls in Javascript placed in a js sub-directory but...well...it didn't do anything with the CSS there.
Carlos
I then include that css file as usual at the top of my view.php file like so...
<link rel="stylesheet" media="screen" type="text/css" href="view.css">
It works but I am wondering if there is some other way that I should be doing this?
For example I recently found out that adding Javascript at the top of my view.php file manually inside SCRIPT elements wasn't the preferred way to do that. Just wondering if maybe there is something similar with respect to external CSS files respecting a best practices way of doing things that does not involve putting the code above at the top of my view.php file.
I tried creating a CSS sub-directory off the block root to see if C5 might pull that in automatically like it pulls in Javascript placed in a js sub-directory but...well...it didn't do anything with the CSS there.
Carlos
Is this a block that you created? You should just be able to place the view.css file in the same directory as the view.php file and C5 does the rest; no <link> tag needed.
Hi SkyBlueSofa,
Yes...this is a block that I am creating pretty much from scratch though I am looking at other existing blocks to get some idea as to how to do things.
That's interesting what you say about C5 automatically pulling it in.
I am going to try that and see if that works.
Carlos
Yes...this is a block that I am creating pretty much from scratch though I am looking at other existing blocks to get some idea as to how to do things.
That's interesting what you say about C5 automatically pulling it in.
I am going to try that and see if that works.
Carlos
Hmmm...interesting.
Sure enough...C5 does pull it in even if I do not explicitly say to do so in my blocks view.php file.
But...only if it is called view.css
C5 won't pull in the css file if it is called something else.
Where is this kind of C5 "magic" documented? I mean it's great getting this kind of insight from everyone here but quite frankly an absolutely pain in the butt having to find it here and there in bits and pieces.
I am specifically talking about the "magic" of doing things like pulling in a particularly named css file from inside the block directory, pulling in JS files from inside a js sub-directory, and other such "magic".
Carlos
Sure enough...C5 does pull it in even if I do not explicitly say to do so in my blocks view.php file.
But...only if it is called view.css
C5 won't pull in the css file if it is called something else.
Where is this kind of C5 "magic" documented? I mean it's great getting this kind of insight from everyone here but quite frankly an absolutely pain in the butt having to find it here and there in bits and pieces.
I am specifically talking about the "magic" of doing things like pulling in a particularly named css file from inside the block directory, pulling in JS files from inside a js sub-directory, and other such "magic".
Carlos
C5 will pull in any css or js that are in the (block)/css or (block)/js directories automagically. It will also pull in the view.css in the blocks root automagically.
I find this method a bit tricky when overriding blocks; however, that is how it's done. For more information on the subject, check out Remo's book from Packt Publishing. It's a wonderful resource and well worth the cash.
I find this method a bit tricky when overriding blocks; however, that is how it's done. For more information on the subject, check out Remo's book from Packt Publishing. It's a wonderful resource and well worth the cash.