Proper Syntax For setCustomTemplate()?

Permalink
I know the function is defined like this:

setCustomTemplate(string $btHandle, string $temp)

But what is the proper syntax for the $temp? I would like to assign my custom template located at packages/brp/blocks/content/templates/brp_blog_post.php to a content block.

This does not seem to work:

setCustomTemplate('content', 'brp_blog_post);

What is correct?

bobrocke
 
enlil replied on at Permalink Reply
enlil
could it be you're missing the last " ' " after brp_blog_post ??
bobrocke replied on at Permalink Reply
bobrocke
No. I mistyped it for the post. I wish it had been that!
Gingebean replied on at Permalink Reply
Gingebean
Hi there I think it is
$a->setCustomTemplate('content','templates/your_custom_template.php');
or just
$a->setCustomTemplate('content','your_custom_template.php');

it the .php that will make it work

GB
bobrocke replied on at Permalink Reply
bobrocke
Dang. Neither of those combinations did the trick. :(

I wonder if I have something else wrong?

$a = new SmartyArea('Main');
$a->setCustomTemplate('content', 'templates/brp_blog_post.php');
$a->display($c);


I know the type of block that was created is a content block because

class SmartyArea extends Area {


And because when I edit that block, the dialog calls says Edit Content.

But is it really content?

I know brp_blog_post.php is at:

packages/brp/blocks/content/templates/brp_blog_post.php

?
Gingebean replied on at Permalink Reply
Gingebean
ooops I must of hit f5... repost sorry
Gingebean replied on at Permalink Reply
Gingebean
to find out if is really a content block

what is the name of the block when you go to "add block" menu

Can you add the template manually by using the custom template option in the menu ?
bobrocke replied on at Permalink Reply
bobrocke
Yes, when I add a block it's a "content' block.

And also yes, I can apply a custom template, in fact the template I want, to the block after the fact.

I just want to do it "automatically."
Gingebean replied on at Permalink Reply
Gingebean
Hmmmm does your smartyArea Class have a setCustomTemplate() function in it that maybe is overriding the Area class ?

I am unfamiliar with this class so if you could post it full source it would be helpful thanks
bobrocke replied on at Permalink Reply
bobrocke
No, the SmartyArea class has no setCustomTemplate Function.

Here's the whole thing:

if (!class_exists('SmartyArea')){
   Loader::model('area');
   class SmartyArea extends Area {
      public function display(&$c, $alternateBlockArray = null){
         $sp = Loader::helper('smartypants', 'brp');
         $c = Page::getCurrentPage();
         /* Start buffering, render into the buffer, and then use the
            buffer's contents to feed to SmartyPants */
         ob_start();
         parent::display($c, $alternateBlockArray);
         $html = ob_get_contents();
         ob_end_clean();
         echo $sp->smartypants($html);
      }
   }


And thanks for your continued help!
Gingebean replied on at Permalink Reply
Gingebean
can u send a zip and i will do some testing
bobrocke replied on at Permalink Reply
bobrocke
Great! What do you need in the .zip?
Gingebean replied on at Permalink Reply
Gingebean
either the brp package or all the needed helpers and classes
and anything related thanks
bobrocke replied on at Permalink Reply 1 Attachment
bobrocke
Here' s the package. Thanks for the help.
Gingebean replied on at Permalink Reply
Gingebean
cant seem to download it
bobrocke replied on at Permalink Reply 1 Attachment
bobrocke
Hmmmm.

Here's another try...
Gingebean replied on at Permalink Reply
Gingebean
k I have done some testing and I think the problem is coming from cache

try this
turn off block cache in the dash board

make sure you have the format

$a->setCustomTemplate('content','templates/brp_blog_post.php');
.

add a content block and hit publish it should work now

Now I don't understand why this happens for the content block because for other block type like autonav it works fine with cache turned on

hope this helps

GB
bobrocke replied on at Permalink Reply
bobrocke
Dang! Still no joy.

I already had the block cache off, but I checked it again to be sure. And then I cleared the concrete5 cache and my Firefox cache. Same problem.

I'll keep poking at this to see if I can find something else. Thank you for your help, so far!
Gingebean replied on at Permalink Reply
Gingebean
Weird cos is it working fine here
JohntheFish replied on at Permalink Reply
JohntheFish
Are you trying to set a block template as an area template?

I have never looked in to what you are doing.

From a block controller you can do
$blockObject = $this->getBlockObject();
if (is_object($blockObject)) {
  $blockObject->setCustomTemplate($template); // template handle
}