Calling a specific block area from template

Permalink
How do you call a certain collection ID with a specific block area (bID) from a template file?
I like to reuse the same Footer on all pages, hardcoded in the template. I don't want to use page default.

griebel
 
andrew replied on at Permalink Reply
andrew
Try this. Let's say the page ID that contains the block you want to reference is 300, and the area that contains the block(s) you want to display is "Footer Special Area."

You'd do this:

<?php
$afs = new Area('Footer Special Area');
$specialPage = Page::getByID(300, "ACTIVE"); 
$afs->display($specialPage);
?>


Does that look right?
griebel replied on at Permalink Reply
griebel
Thanks a lot, your code snippet worked perfectly.
thetaxi replied on at Permalink Reply
This does work fine and the correct content is added but the css and js for the block is not automatically picked up and added to the header.

In order reduce the amount of content that must be added to the site, a page has been added called 'Default' with handle 'default'. The page only appears in the navigation when an admin is in edit mode. The admin can add content to any area on this default page. When any other page is viewed and there is no content available for an area, then the matching area is used from the default page.

This works perfectly except that again, the view.css, view.js, etc. are not being added to the head.

I am assuming this is because by the time the template is being parsed that the header files have already been handled.

Is there a better way to do this? Figured I might try handling the content selection in the controller. Tried adding a default controller in controllers/page_types but that does not appear to be an option (seems to be ignored).

Here is a sample of the code in use. This is from an included footer template file from with a theme. The footer include is called by the default.php for the theme.

// grab Footer area blocks for current page
$blocks = $c->getBlocks( 'Footer' );
// if we are editing or if there are blocks, then show area
if ( $c->isEditMode() || $blocks )
{
    $a = new Area( 'Footer' );
    $a->display( $c );
// otherwise grab the content from the same area on the default page
} else {            
    $default = Page::getByPath( "/default" );   
    $blocks = $default->getBlocks('Footer');
    foreach ($blocks as $block)
    {
        $block->display();
    }


Works fine too if I grab the area and display it instead of the blocks. But again, it does not add the appropriate css and js to the head.

Any help would be greatly appreciated. Can;t be the first person to try and setup default content to be displayed if nothing is available for an area.
jordanlev replied on at Permalink Reply
jordanlev
There's unfortunately some things in the C5 core code that aren't hooked up right, and there are situations where view.css/view.js files don't show up when they should.

You might try the free "Global Areas" addon in the marketplace to do what you want to do instead of the code you have -- I'm not sure but it's possible it handles the js/css files better (maybe).