How to implement a fixed block with custom template on a page

Permalink
I want to include a autonav block on my theme pages. It should not be editable by the users, but be part of the template. And it must be displayed in a custom template.

I already used this:

$bt_main = BlockType::getByHandle('autonav');
 $bt_main->controller->displayPages = 'current';
 $bt_main->controller->orderBy = 'display_asc';
 $bt_main->controller->displaySubPages = 'none';
 $bt_main->render('view');


to implement a sidebar subnavigation on the page. But the main navigation needs a custom template. (located in /blocks/autonav/templates/)

How do I include an autonav block, but with a custom template?

 
synlag replied on at Permalink Reply
synlag
$bt_main->setCustomTemplate('your_template_name');
Remo replied on at Permalink Reply
Remo
no, setCustomTemplate is what you usually use when you want to set a template for a block instance.

You should replace "view" with your "template_name"..
Kalindor replied on at Permalink Reply
Thanks for the reply.

Actually, replacing 'view' with 'templates/MY_TEMPLATENAME' did the trick. Without the 'templates/' part concrete did not find the correct path.
jordanlev replied on at Permalink Reply
jordanlev
Note that doing this may cause problems if you want a form in your block -- when I tried this, the $this->action() function would not output anything so my forms were not being submitted back to the controller.
Remo replied on at Permalink Reply
Remo
it's possible that you have to include the css and js files manually because the page controller doesn't know that there's a block on the page and therefore doesn't include the css and js files in the header..

but including them manually should do the trick!
Proteus replied on at Permalink Reply
Proteus
I've had to do this a couple of times in this situation, usually when I needed a block in the Global Scrapbook to be hardwired into a page template or site wide (you often need to do this if make a "Page Default" equivalent for Single Pages). Something like this:

In the <head>:
$loginBlock = Block::getByName('Login');
if ($loginBlock && $loginBlock->bID) {
         print "<link href=\"".$this->url('')."blocks/login/templates/YOUR_TEMPLATE_HERE/view.css\" rel=\"stylesheet\" type=\"text/css\" media=\"all\"/>"; }


And then where the block needs to appear:
if ($loginBlock && $loginBlock->bID) {
                     $loginBlock->display();
                  } else {
                     $a = new Area('Login');
                     $a->display($c);
                  }


It would be nice if all that wasn't necessary.
Tony replied on at Permalink Reply
Tony
i've run into that same problem with $this->action(). seems to not function when you're hardcoding blocks to a page. just posted a comment about it here;http://www.concrete5.org/index.php?cID=28147...