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:
$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

View Replies:
shahroq replied on at Permalink Reply
shahroq
You can create a page_list template, it can contains cID and any attributes you would need, then
$block->display('my_template');
Sepehr replied on at Permalink Reply
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
shahroq replied on at Permalink Reply
shahroq
What about:
$block->setCustomTemplate( 'your_template.php' );
$block->render();
Sepehr replied on at Permalink Reply
Not working
WillemAnchor replied on at Permalink Reply
WillemAnchor
try:
$bv = new BlockView($block);
   $bv->setAreaObject($a);
   $bv->render('view');
Sepehr replied on at Permalink Reply
Not working. Also it's for dashboard app, so there is no area involved.
WillemAnchor replied on at Permalink Reply
WillemAnchor
Are you really sure ?

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