Hardcoded dynamic blocks and form action

Permalink 1 user found helpful
Hi
I've got some problem with a single_page and blocks. How do i add the $view to the blocks view.php if the block is called by a single_page?

Here is the example:

this is the part of my single page to add the block:
$bt_pass = BlockType::getByHandle('ts_reporting_customer');
$bt_pass->controller->adrID = $_GET['adrID'];
$bt_pass->render();


in the view.php of the block i would like to add a form
<form method="post" action="<?= $view->action('form_save_data') ?>">


this returns
Call to a member function getAreaHandle() on null


Thanks in advance,
Steff

Steff
 
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
You can specify a template with
$bt->render('templates/my_template');

(see https://github.com/shahroq/whale_c5_cheat_sheet/blob/master/README.m... );

For interaction, you need a block ID so the routing for actions knows which block controller it is working with. You don't get a bID with hard coded blocks.

For your use-case, you could code the functionality directly into a single page (ie, not in a block) and use the single page controller to handle the form interaction. Or you could put the blocks in a stack, and hard-code the stack display into the single page.

Hard coded blocks are not cached, so can have a negative impact on performance and are generally a trick that is now obsolete and best avoided.
Steff replied on at Permalink Reply
Steff
Thank you JohntheFish

I now use the single_page controller to redirect to existing entity-controllers. Thanks