add blocks to template

Permalink
hi there

As most of you know, it is very simple to add the AutoNav block to a template. This is great. I made a simple block to parse xml-data. I would like to add this block also to a page-template. Can anyone tell me, how to add other blocks then the AutoNav block to the template?

Thanks and kind regards,
Steff

Steff
 
cgrauer replied on at Permalink Reply
cgrauer
Same way as autonav:

$bt = BlockType::getByHandle('your_block_handle');
$bt->controller->yourBlockParameter = 'value';
# more parameters...
$bt->render('view');


Some blocks need special care because they use data from more than one table, and some need addiditional action (like slideshow for example). You also may use custom templates with render().
Mnkras replied on at Permalink Reply
Mnkras
im wondering how to add a editable block via a theme,

like the person can click on it and hit edit.

Any help is appreciated,

Mike
cgrauer replied on at Permalink Reply
cgrauer
I don't think this to be possible without hacking a lot. To be editable, the block has to reside in the database and not in the template.
Steff replied on at Permalink Reply
Steff
Thank you cgrauer

this helped me a bit further.
$bt->controller->URL = 'myLink';


This should pass the myLink to my controller.php. Could you please tell me, how to access this now?

Thanks,
Steff
Steff replied on at Permalink Reply
Steff
got it. it's as simple as it can be.

controller.php
function getURL(){
return $this->URL;
}


view.php
$URL = $controller->getURL();


that's the whole thing.

Thank you all.
jordanlev replied on at Permalink Reply
jordanlev
Note that doing this may cause problems if you want a form in your block -- when I tried this, the $this->action() function would not output anything so my forms were not being submitted back to the controller.
Tony replied on at Permalink Reply
Tony
yeah, this is a pain. does $this->action() require a block id in order to work? lately i've been not using $this->action on blocks because of this, and have just been doing the submit logic with the block controller's view method. that comes with another set of problems though (yu've got to manually use the token and have to do some stuff to make it handle multiple instances on the same block on a page).
Steff replied on at Permalink Reply
Steff
jordanlev,
thanks for the hint. did you find an other solution to the $this->action() problem?
matogertel replied on at Permalink Reply
matogertel
Another trick is to use the tools. An example view.php would be:
<?php
defined('C5_EXECUTE') or die(_("Access Denied.")); 
$tools = Loader::helper('concrete/urls')->getBlockTypeToolsURL(BlockType::getByID($b->getBlockTypeID()));
$action = $tools."/my_action_script"; //should be in blocks/myblock/tools/my_action_script.php
?> 
<form action="<?php echo $action ?>" method="post">
</form>
Steff replied on at Permalink Reply
Steff
thank you matogertel.
this could be a way to solve the problem.

by the way. what is the official way to get the
$bt->controller->URL('myURL');
variable from an block which is included into a template?

am i using the correct way with this in my controller?
function getURL(){
return $this->URL;
}