How to $bvt->setBlockCustomTemplate ?
Permalink 2 users found helpful
Hey guys,
I've been trying to use the $bvt->setBlockCustomTemplate in a block I'm creating but I have a hard time applying the set with the data I specify in the Block Edit mode when saved.
What I did in my EDIT form is:
and in my controller SAVE function I've added this:
So I have all the templates available for that block generated in my SELECTBOX no problems but when I select one and hit SAVE, it's does not apply it and it does not return me any error.
Help ? lol
Thanks
I've been trying to use the $bvt->setBlockCustomTemplate in a block I'm creating but I have a hard time applying the set with the data I specify in the Block Edit mode when saved.
What I did in my EDIT form is:
<?php global $c; $bt = $controller->getBlockIdCarl(); $b = $controller->getBlockTypeIdCarl(); $templates = $bt->getBlockTypeCustomTemplates(); $txt = Loader::helper('text'); ?> <select name="settemplate" id="settemplate"> <option value="">(<?php echo t('None selected')?>)</option> <?php foreach($templates as $tpl) { ?> <option value="<?php echo $tpl?>" <?php if ($b->getBlockFilename() == $tpl) { ?> selected <?php } ?>><?php if (strpos($tpl, '.') !== false) { print substr($txt->unhandle($tpl), 0, strrpos($tpl, '.')); } else { print $txt->unhandle($tpl);
Viewing 15 lines of 19 lines. View entire code block.
and in my controller SAVE function I've added this:
public function save($data) { $b = $this->getBlockObject(); $bvt = new BlockViewTemplate($b); $bvt->setBlockCustomTemplate($data['settemplate']);
So I have all the templates available for that block generated in my SELECTBOX no problems but when I select one and hit SAVE, it's does not apply it and it does not return me any error.
Help ? lol
Thanks
One of Remo's Free blocks does that, look around in the MP
Hi Mnkras, are you sure it was remos ? Because I checked all of his addon and none of them have this in it.
yep, his expand collapse, your trying to get custom templates in the edit dialog right?
and in the save function you need
I think thats all the code you need,
//in edit form <select name="layout"> <option value="">(<?php echo t('None selected') ?>)</option> <?php $templates = $controllerObj->getTemplates(); $currentTemplate = $controllerObj->getCurrentTemplate(); foreach ($templates as $template) { $selectedTemplate = ""; if ($currentTemplate == $template) { $selectedTemplate = ' selected="selected" '; } echo "<option {$selectedTemplate} value=\"{$template}\">{$template}</option>"; } ?> </select>
//controller function getTemplateByDirectory() { $templates = scandir(dirname(__FILE__) . '/templates'); $templates = array_filter($templates,array($this,'filterDirectories')); return $templates; } /** * Returns all available templates for this block */ function getTemplates() { $blockObject = $this->getBlockObject(); if (is_object($blockObject)) { $bt = BlockType::getByID($blockObject->getBlockTypeID());
Viewing 15 lines of 30 lines. View entire code block.
and in the save function you need
$blockObject = $this->getBlockObject(); if (is_object($blockObject)) { $blockObject->setCustomTemplate($data['layout']); }
I think thats all the code you need,
btw, some of the things he does in here can be swapped out for c5 methods and such
its working, I was trying to use: setBlockCustomTemplate() instead of setCustomTemplate();
Many thanks. :D
Many thanks. :D
NP man :)