api for render block programmatically
Permalink
I'm looking for a way to render a block programmatically. What i exactly want to do is get a stack, and render some of the block inside with my own created template. It's for a dashboard app and i call these via ajax.
What i have done so far is, first get the stack by id, then render blocks inside one by one like this:
Now what should i want to do is display block with a custom template, i tried:
and
But none of them worked, any ideas would be appreciated.
Thanks
What i have done so far is, first get the stack by id, then render blocks inside one by one like this:
$stack = Stack::getByID($stackID); $blocks = $stack->getBlockIDs(); foreach ($blocks as $key => $value) { $block = Block::getByID($value['bID']); $block->display(); }
Now what should i want to do is display block with a custom template, i tried:
$block->display('my_template');
and
$block->setCustomTemplate( 'your_template.php' ); $block->render();
But none of them worked, any ideas would be appreciated.
Thanks
You can create a page_list template, it can contains cID and any attributes you would need, then
I checked that and it only works for default block template (view.php). Anything other than that result this error:
Warning: include(/concrete/blocks/page_list/page_list_json.php): failed to open stream: No such file or directory in \concrete\core\libraries\block_view.php on line 311 Warning: include(): Failed opening '\concrete/blocks/page_list/page_list_json.php' for inclusion (include_path='/libraries/3rdparty;\concrete/libraries/3rdparty;.;C:\php\pear') in \concrete\core\libraries\block_view.php on line 311
What about:
$block->setCustomTemplate( 'your_template.php' ); $block->render();
Not working
try:
$bv = new BlockView($block); $bv->setAreaObject($a); $bv->render('view');
Not working. Also it's for dashboard app, so there is no area involved.
Are you really sure ?
Take a look at ...\concrete5.7.5.6\concrete\single_pages\dashboard\blocks\stacks\detail.php
Just get the blocks and render them as my the other snippet
Take a look at ...\concrete5.7.5.6\concrete\single_pages\dashboard\blocks\stacks\detail.php
<?php $a = new Area(STACKS_AREA_NAME); $a->display($c); ?>
Just get the blocks and render them as my the other snippet