Manually including Calendar block in package template

Permalink
V8.4.0
I expected the following to work but nothing is output to the browser by render(), just the template HTML, what am I missing? The values were taken from the DB entries for a block added in edit mode from the bt Calendar table, which displayed fine.

$bt = BlockType::getByHandle('calendar');
$bt->controller->caID = 1; // calendar ID
$bt->controller->calendarAttributeKeyHandle = ''; // calendar ID
$bt->controller->filterByTopicAttributeKeyID = 70; // topic filter ID
$bt->controller->filterByTopicID = 1; // topic ID
$bt->controller->viewTypes = '["month","basicWeek"]'; // calendar ID
$bt->controller->viewTypesOrder = '["month_Month","basicWeek_Week"]'; // calendar ID
$bt->controller->defaultView = 'month'; // calendar ID
$bt->controller->navLinks = 0; // calendar ID
$bt->controller->eventLimit = 0; // calendar ID
$bt->controller->lightboxProperties = '["ak_71","ak_72","ak_73","ak_75","ak_78","ak_79"]'; // calendar ID
$bt->render();


I tried using $bt->controller->set(name, value) also with the same result

Thanks

surefyre
 
surefyre replied on at Permalink Reply
surefyre
I believe I found the solution or at least something that moves the solution forwards.

The calendar block relies on the Block ID which isn't present when you do a manual include as I'm doing (this is to dynamically filter the calendar based on the user viewing it).

In the built-in view we have this:
<div class="ccm-block-calendar-wrapper" data-calendar="<?=$bID?>"></div>


Which gives rise to a JS error when there's no bID. By creating a custom template e.g. packages/mypackage/blocks/calendar/templates/myview.php I am able to render the block using:
$bt->render('templates/myview');


In myview.php I simply set a bID manually with:
$bID = 1000;


It now renders a calendar.

I assume this will only allow one calendar per page with this template although you could generate unique bID values if you wanted to I suppose though I don't need more than one.
surefyre replied on at Permalink Best Answer Reply
surefyre
In the end I copied the calendar block into my package and renamed it then altered the controller to suit my needs.
JeffPaetkau replied on at Permalink Reply
JeffPaetkau
Thanks, this helped!

edit: Error I was getting was
Call to a member function getAreaHandle() on null