Anyone know how to specify a custom template for a block in php?....

Permalink 1 user found helpful
Hey all! Hope you're having good days! ... So here's the situation I'm in.

I've created custom templates that extend the concrete 'autonav' block. This allows me to generate a wonderful drop down menu. Sweet. But I don't want the end user of the admin to have to add this and set it up on every page, rather, I want to add it to my homepage / default template and have it populate every other page automatically. So it's only editable in one area. I've accomplished this in the past with other normal blocks by using this method below:

<?php 
    $footer = new Area('Header Text Title');
    $ footer->setBlockLimit(1);
    if ($c->cID != "1") {
      //If we are not currently displaying the home page – grab the footer from the homepage
      $homePage = Page::getByID(1, "ACTIVE");
      $footer ->display($homePage);
    } else {
      //If we are on the homepage use the current page variable so the block can be updated.
      $footer ->display($c);
    } 
?>


The problem here is that I'm extending autonav with a custom template, but I can't edit the block on any other pages because it only gets built once on the homepage.

The problem is that when it displays on all other pages in the site, it uses the autonav default template ... which is not my beautiful drop down menu with custom styling.

Do you know how to set the template with PHP? Hope this makes sense. Any help is much appreciated and I thank you in advance!!!

 
mdzoidberg replied on at Permalink Reply
mdzoidberg
You can do this within your template;

$bt_main =BlockType::getByHandle('autonav');
$bt_main->controller->displayPages ='below';
$bt_main->controller->orderBy = 'display_asc';                    
$bt_main->controller->displaySubPages = 'all';
$bt_main->controller->displaySubPageLevels = 'all';
$bt_main->render('templates/your_template');


Look at the AutoNav block controller for more information on custom settings.

Cheers.
sketch2k replied on at Permalink Reply
Thanks for the info! (Awesome Avatar ;))

EDIT:

Found some extra resources for anyone else who wants to accomplish something similar here.

http://www.concrete5.org/community/forums/customizing_c5/how_to_aut...

And from there I found this awesome video which explains something I should've just found ... ages ago:

http://www.concrete5.org/help/editing/scrapbook_defaults/...

... It doesn't make me feel warm and fuzzy inside to use that method, but since I'm a total PHP newb... It'll do :)

Thanks everyone.
N-

ORIGINAL POST BELOW:

So this is pretty close to perfect but I'm not understanding the last line (modified for my purpose):
$bt_main->render('templates/drop_down_menu/view');


I think it has to do with how I've got it all set up.

The original 'autonav' block still exists in:

webroot/concrete/blocks/autonav

and I've created a new template for it in:

/webroot/blocks/autonav/templates/drop_down_menu/

Notice that it's not in the concrete folder. So ... inside drop_down_menu/ I have a view.php and a view.css file that styles it all.

In this case ->render('your template') is ... being referenced, but the view.css that it requires is not being read in.

Thoughts? Alternative methods? Work Arounds?
ScottC replied on at Permalink Reply
ScottC
sure.

you can introduce a mechanism to check cID and all of that but:

$a = new Area('nav');

$a->setCustomTemplate('auto_nav','carrots');
//so any auto_nav block type will render a template of carrots.php if present.

$a->display($c);

That's it.

Test to make sure, as you might need the carrots to be carrots.php, but that's what you do.