How to call a block from a template ?
Permalink
Hi,
I'm looking to display a block from my template. I don't want to use the Defauts feature to add the block to all my page but code that in the php template file to avoid my customer can modify that...
I know how to call an autonav block but I can't success to include a content block. Any idea ?
Thanks.
I'm looking to display a block from my template. I don't want to use the Defauts feature to add the block to all my page but code that in the php template file to avoid my customer can modify that...
I know how to call an autonav block but I can't success to include a content block. Any idea ?
Thanks.
I'm pretty sure I saw something on the forum about this earlier, and now searching again for it, since I also need to do this. If I find it, I'll post a link to it here.
Thanks, but it's not exactly what I'm looking for... I want to call an existing block.
<?php //Instantiate the block. $bt_links = BlockType::getByHandle('blockname'); //Set Block values. $bt_links->parameter = value; //Use default render action. $bt_links->render('view'); //OR render using a template. $bt_links->render('path/templateName'); //OR use a custom function to manipulate the block for custom display. foreach ($bt_links as $bt_links){ some->action; } ?>
all thats based on info from remos site.
http://www.codeblog.ch/category/concrete5/...
specifically
http://www.codeblog.ch/2009/04/concrete5-blocks-within-templates/...
I know how to create a new block like that code but not how to re-use an existant block... like saying.. call the block #48.
I'm trying that, but not exactly that yet...
I'm trying that, but not exactly that yet...
$b = Block::getByID(48); $bv = new BlockView(); echo $bv->render($b, 'view');
Here's some code I wrote a while ago:
It fetches a block with the handle music_control out of the scrapbook. I'm not sure if this is the proper way, but it shows you how to display an already existing block..
$cGlobal = Page::getByPath('/dashboard/scrapbook/global'); $blocks = $cGlobal->getBlocks("Global Scrapbook"); foreach($blocks as $b) { ... if ($b->getBlockTypeHandle() == 'music_control') { $b->display(); } }
It fetches a block with the handle music_control out of the scrapbook. I'm not sure if this is the proper way, but it shows you how to display an already existing block..
I guess it should be easy as this:
but I haven't tested it..
$b = Block::getByID(48); $b->display();
but I haven't tested it..
anyone any luck or is it me?
but I had the error in my phperr.log :
Fatal error: Call to a member function getCollectionID() on a non-object in area.php on line 117
Like here :http://www.concrete5.org/index.php?cID=10634...
Fatal error: Call to a member function getCollectionID() on a non-object in area.php on line 117
Like here :http://www.concrete5.org/index.php?cID=10634...
where you have your, render, 'view', the 'view' could be 'templates/wonkyview' or something of that sort, any file off of the blockpath at the view depth.
<?php $newArea = new Area ('NEW'); $newAreaBlocks = $newArea->getAreaBlocksArray($c); $newBlock = Block::getByID($blockID); $newAreaBlocks = array_push($newAreaBlocks,$newBlock); $newArea->display($c, $newAreaBlocks); ?>
I'm not 100% sure but that might be wat u mean. There's a Block::duplicate($nc) command, i'm not 100% sure what it does, but it might come in handy.
it's duplicates a block instance in the database.
Needed if a new page version is created (each version creates a new block version as well)
Needed if a new page version is created (each version creates a new block version as well)
wasnt aware of that. thanks for that bit of info.
There seems to be a Concrete5 bug because if I am grabbing a block like you guys described with e.g.
the issue is that the HTML that got added with TinyMCE gets screwed a bit, see http://www.concrete5.org/community/forums/customizing_c5/confusion-...
$b = Block::getByID(48); $bv = new BlockView(); echo $bv->render($b, 'view');
the issue is that the HTML that got added with TinyMCE gets screwed a bit, see http://www.concrete5.org/community/forums/customizing_c5/confusion-...