Added Single Page. Custom CSS Not Working

Permalink
Hi -

Got a single page up and running with a bunch of HTML in it.

Trying to get the associated style.css file to be referenced.

For some reason, it's not.

Here's what I've got:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css"/>
...
</head>

Both the file.php and style.css are in the same folder. I've tried adding the full path and different partial paths to style.css with no success.

What little step am I missing?

 
jordanlev replied on at Permalink Reply
jordanlev
What you're missing is that C5 (as with all database-backed CMS's) serves pages at a URL that does not necessarily correspond to the location of the code. Think about it: the address for the single_page is probably something like example.com/some_page -- but the single_page file is in /single_pages/some_page.php.

Another thing to be aware of is that the contents of your singke_page get outputted within your theme's view.php template -- so that template is probably already including a <head> (and hence your 2nd <head> gets ignored by the browser.

Anywho... either put your styles into your theme's css file, or put your own CSS file in your site's top-level "CSS" directory, then create a controller for the single_page that calls $this->addHeaderItem(Loader::helper('html')->css('your_stylesheet.css)); in its view function.
mhawke replied on at Permalink Reply
mhawke
So what do I do in this case. My login single page renders fine 95% of the time unless the user is sent there by C5 as a result of some permission issue. For example, if I'm not logged in but I try to go directly to the dashboard by entering '/index.php/dashboard' I get sent to the login page. In that case, the css/js for my Sooperfish autonav doesn't get called and I end up with a missing navigation bar with all the links listed as per the attached screenshot. The css and js are stored in the traditional '[root]/blocks/autonav/templates/Sooperfish'.

Any thoughts on where I should put the css and js?
jordanlev replied on at Permalink Reply
jordanlev
Oh, so you're talking about overriding the system's login page, not creating your own single_page? This is a different issue then. What happens is that hitting a page someone doesn't have permission to *looks* like it's redirecting to the login page, but it's not actually be redirected to the login page -- instead it's being shown the "page_forbidden" page (I think).

What I usually do to solve this problem is override the page_forbidden controller and tell it to redirect to the login page instead of just displaying a portion of the login form. This can be achieved by creating a new file in your site's top-level "controllers" directory, called "page_forbidden.php", with this code in it:
<?php defined('C5_EXECUTE') or die("Access Denied.");
//Modify built-in C5 "page forbidden" controller:
// Redirect to the login page instead of just rendering its template
// (so custom styles show up properly).
Loader::controller('/login');
class PageForbiddenController extends LoginController {
   public function view() {
      global $u;
      if (!is_object($u) || !$u->isLoggedIn()) {
         $redirect_to = '/login';
         $v = View::getInstance();
         $c = $v->getCollectionObject();
         if (is_object($c)) {
            $cID = $c->getCollectionID();
            if($cID) {
mhawke replied on at Permalink Reply
mhawke
Thanks jordanlev. I was at my wit's end trying to figure out why my login page wasn't pulling in it's own css/js.

UPDATE: Worked like a charm! Thanks!