Block JS & CSS not loading on page_not_found page
Permalink
Hi,
I'm using a Lightbox Gallery block (Jordan Lev's Simple Image Gallery with the FancyBox lightbox effect) in the footer of my site. Everything is working fine, except for the "Page Not Found" page. I added a "page_not_found.php" file to my theme to customize the error message displayed (see it here by actually typing the URL for the page_not_found page:http://tinyurl.com/7xg3vmd ).
BUT if you are directed to that page because you typed in an invalid/non-existent URL (http://tinyurl.com/7nj288p ), the gallery is not loading the JS and CSS called for in the block, so the gallery doesn't display correctly AND doesn't trigger the lightbox).
I'm guessing it has something to do with the pathing to the block when you are re-directed to the page_not_found page... but can't identify why/how.
Has anyone else encountered this kind of behavior before? And, if so, do you have any solutions?
I'm using a Lightbox Gallery block (Jordan Lev's Simple Image Gallery with the FancyBox lightbox effect) in the footer of my site. Everything is working fine, except for the "Page Not Found" page. I added a "page_not_found.php" file to my theme to customize the error message displayed (see it here by actually typing the URL for the page_not_found page:http://tinyurl.com/7xg3vmd ).
BUT if you are directed to that page because you typed in an invalid/non-existent URL (http://tinyurl.com/7nj288p ), the gallery is not loading the JS and CSS called for in the block, so the gallery doesn't display correctly AND doesn't trigger the lightbox).
I'm guessing it has something to do with the pathing to the block when you are re-directed to the page_not_found page... but can't identify why/how.
Has anyone else encountered this kind of behavior before? And, if so, do you have any solutions?
Hey Jero,
Thanks for the response. It is true that "Page Not Found" is a single page... but, from what I understand, if you add a "page_not_found.php" file to your theme, C5 uses that as an over-ride for the default, thereby NOT loading up "view.php".
So my "page_not_found.php" file is almost identical to my "default.php" file... except that I don't have any areas on it... and just put the HTML content I want displayed. Otherwise, they're identical (see attached ZIP file).
Thanks!
- John
Thanks for the response. It is true that "Page Not Found" is a single page... but, from what I understand, if you add a "page_not_found.php" file to your theme, C5 uses that as an over-ride for the default, thereby NOT loading up "view.php".
So my "page_not_found.php" file is almost identical to my "default.php" file... except that I don't have any areas on it... and just put the HTML content I want displayed. Otherwise, they're identical (see attached ZIP file).
Thanks!
- John
You're right about the template override. I often find it useful to put the tempalte name into the template as an html comment - then I know which template I'm dealing with by looking at the source.
How are you getting the image gallery into the footer? I suspect that's part of the issue here. If a block is pulled in using code, then the block's JS/CSS will not be added automatically. Perhaps posting elements/*.php might help?
How are you getting the image gallery into the footer? I suspect that's part of the issue here. If a block is pulled in using code, then the block's JS/CSS will not be added automatically. Perhaps posting elements/*.php might help?
I actually added the block directly to the "page_not_found" page in Concrete5... by navigating to it while logged in, editing it and putting the block into the "FooterGallery" area that is coded into the "include-footer-content.php" file that is called from "footer.php" (see attached files).
I did that after it didn't work through page_type defaults... and then was disappointed when it didn't work again. ;)
I'm wondering if I shouldn't just create a different version of the header.php & footer.php files where I hard-code in the CSS and JS file links and include them in my page-not-found.php. Since this is a "one-off" type of page, it's not that much work. I just thought it was strange that the single page doesn't seem to include JS/CSS from blocks inserted on the page.
Thanks for the help.
- John
I did that after it didn't work through page_type defaults... and then was disappointed when it didn't work again. ;)
I'm wondering if I shouldn't just create a different version of the header.php & footer.php files where I hard-code in the CSS and JS file links and include them in my page-not-found.php. Since this is a "one-off" type of page, it's not that much work. I just thought it was strange that the single page doesn't seem to include JS/CSS from blocks inserted on the page.
Thanks for the help.
- John
Ooops... forgot to attach the files. DOH!
Here they are!
Here they are!
Just as an update... I tried adding in hardcoded links to the FancyBox CSS and JS into the header & footer of the page_not_found.php file, respectively. And... when being re-directed to that page by entering in an invalid URL, the gallery STILL doesn't work.
So... I'm thinking this is more of a C5 issue than something specific to the plugin: when C5 is redirecting the output for an invalid URL to the page_not_found.php page, somehow it isn't passing or allowing access to the correct pathing, or something. Because if you enter the URL to go directly to the page_not_found.php file, everything works.
Thoughts?
Thanks!
- John
So... I'm thinking this is more of a C5 issue than something specific to the plugin: when C5 is redirecting the output for an invalid URL to the page_not_found.php page, somehow it isn't passing or allowing access to the correct pathing, or something. Because if you enter the URL to go directly to the page_not_found.php file, everything works.
Thoughts?
Thanks!
- John
Latest update: I got it working (see this thread:http://www.concrete5.org/community/forums/customizing_c5/single-pag... ). The final solution was that I just created a custom "header.php" to include on the "page_not_found.php" file in my theme and hardcoded the links to the CSS and JS files into it like this:
Inelegant. But it works! ;D
Thanks!
- John
<link rel="stylesheet" type="text/css" media="screen, print" href="<?php print DIR_REL; ?>/blocks/footer_simple_image_gallery/fancybox/jquery.fancybox-1.3.1.css" /> <script type="text/javascript" src="<?php print DIR_REL; ?>/blocks/footer_simple_image_gallery/fancybox/jquery.fancybox-1.3.1.pack.js" /></script>
Inelegant. But it works! ;D
Thanks!
- John
Cool. I think the reason behind this is that when page_not_found is run for a genuine missing page, that the page isn't actually a real page.
I was going to suggest a couple of solutions - in both cases you're going to need to bolt the JS/CSS into your header:
1) create a scrapbook block rename it to "My_Block" and access it like this:
or
Alas, the 2nd example results in a fatal error, because there seems to be a missing method in the controller. This technique works just fine with autonav etc,
The 1st should work for all pages.
I was going to suggest a couple of solutions - in both cases you're going to need to bolt the JS/CSS into your header:
1) create a scrapbook block rename it to "My_Block" and access it like this:
$block = Block::getByName('My_Block'); if( $block && $block->bID ) $block->display();
or
$bc->controller->set('displayColumns',3); $bc->controller->fsID= 1; $bc->controller->btID= 27; $bc->controller->fullWidth= 800; $bc->controller->fullHeight= 600; $bc->controller->enableLightbox= 1 ; $bc->controller->lightboxTransitionEffect= "fade"; $bc->controller->lightboxTitlePosition = 'outside'; $bc->controller->thumbWidth = 50; $bc->controller->thumbHeight= 50; $bc->render('view');
Alas, the 2nd example results in a fatal error, because there seems to be a missing method in the controller. This technique works just fine with autonav etc,
The 1st should work for all pages.
Thanks, Jero! I'll keep option #1 in mind for the future!
Appreciate the help!
- John
Appreciate the help!
- John
and not
although there's no reason why you can't have other page areas, e.g. autonav defined.
So what I'd suggest you do is check that your view.php is identical to your "default.php" page (which if you haven't got one, you should add) and then it should load the JS etc