How to set a Custom Template by hardcode for an Area:
Permalink
Hi,
I try alot but not succeded, for setting a custom template for an area by hardcode for specific blocks in that area.
I am using this code for setting custom template....
Any one know about it????
I try alot but not succeded, for setting a custom template for an area by hardcode for specific blocks in that area.
I am using this code for setting custom template....
<?php $block = BlockType::getByHandle('easynews_list'); $a=new Area('All News Area'); $a->setCustomTemplate($block, 'all_news'); $a->display($c); ?>
Any one know about it????
Hi RealSeen,
Thanks for your reply, you are right to use "templates/..' with this, but unfortunately i got warning error
I search alot for the use of setCustomTemplate() but nothing helpful. !
Thanks for your reply, you are right to use "templates/..' with this, but unfortunately i got warning error
Warning: Illegal offset type in /....../concrete/models/area.php on line 64
I search alot for the use of setCustomTemplate() but nothing helpful. !
Maybe $block is returning an array?
I had a quick look at the error and found this in the Php manual
Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type
Its likely that something in code is not returning the object,
my guess is that something in the customTemplate function is trying to assign an array key to be either an object or array, which in turn suggests something is not being passed through correctly.
Im not fully sure how to use the Page Types, function Ill see if I can find any more info, unless anyone else can help?
I had a quick look at the error and found this in the Php manual
Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type
Its likely that something in code is not returning the object,
my guess is that something in the customTemplate function is trying to assign an array key to be either an object or array, which in turn suggests something is not being passed through correctly.
Im not fully sure how to use the Page Types, function Ill see if I can find any more info, unless anyone else can help?
The Docs suggest the following
$area->setCustomTemplate($btHandle, $template)
so try the following
$area->setCustomTemplate($btHandle, $template)
so try the following
$a->setCustomTemplate('easynews_list','templates/all_news');
As a quick note, the BlockType, returns the object for the Block.
And is used to render the Block on the page, with defined parameters.
So you should be able to get rid of that bit from your code.
The setCustomTemplate appears to take a block handle, not the object my previous reply mentioned.
I should have checked the docs earlier :)
The latest reply should work
regards
And is used to render the Block on the page, with defined parameters.
So you should be able to get rid of that bit from your code.
The setCustomTemplate appears to take a block handle, not the object my previous reply mentioned.
I should have checked the docs earlier :)
The latest reply should work
regards
Hi, sorry! but this is also not working, don't know why. and i also try by changing the block handle but nothing happened. If the concrete also create a directory like Wordpress, then this will be easy to use any method.... Thanks..
Try
$a->setCustomTemplate('easynews_list','all_news.php');
or if its a folder
$a->setCustomTemplate('easynews_list','all_news/view.php');
$a->setCustomTemplate('easynews_list','all_news.php');
or if its a folder
$a->setCustomTemplate('easynews_list','all_news/view.php');
That seems to do it, I guess the function unlike the other template functions do not append the .php?
Hi RealSean,
Thanks for your replies and working on this method. It's now working by placing (.php) at the end of template file, like the below.
So now this is clear to place .php extension at the end of every template file, which is not identified by area methods of concrete5 documentation. Once again thank you for your great work...
Thanks for your replies and working on this method. It's now working by placing (.php) at the end of template file, like the below.
$a=new Area('All News Area'); $a->setCustomTemplate('easynews_list','templates/all_news.php'); $a->display($c);
So now this is clear to place .php extension at the end of every template file, which is not identified by area methods of concrete5 documentation. Once again thank you for your great work...
And I assume "all_news" is a template for the easynews_list?
I am not sure about this but what if you try,
$a->setCustomTemplate($block, 'templates/all_news');
Do you get any errors?