getThemeDefaultBlockTemplates
Permalink 1 user found helpful
Hi all,
I'm building quite a complex theme at the moment, where it's packaged up with a whole bunch of custom block templates.
I've tried to use the getThemeDefaultBlockTemplates() function within page_theme.php to make it default to a particular template for block types, but I'm not getting it to work.
I've got:
When I add a File block to the page it just defaults to the normal view.php, but if my custom block template (with_icon.php) is available if I manually change to it.
Does adding this to page_theme.php require the theme to be reinstalled? Is there some other step required to get this to work?
I'm building quite a complex theme at the moment, where it's packaged up with a whole bunch of custom block templates.
I've tried to use the getThemeDefaultBlockTemplates() function within page_theme.php to make it default to a particular template for block types, but I'm not getting it to work.
I've got:
public function getThemeDefaultBlockTemplates() { return array( 'file' => 'with_icon' ); }
When I add a File block to the page it just defaults to the normal view.php, but if my custom block template (with_icon.php) is available if I manually change to it.
Does adding this to page_theme.php require the theme to be reinstalled? Is there some other step required to get this to work?
I've found that leaving out the php extension makes it look for a view.php inside a folder with that name, while including the file extension makes it look for a template file with that name.
is looking for 'templates/with_icon/view.php'
is looking for 'templates/with_icon.php'
That was it! Thanks!
I just had to change it to:
That does make sense, due the two different ways that block templates can be provides.
I think the doco here isn't quite correct then:
https://www.concrete5.org/documentation/developers/5.7/working-with-...
I just had to change it to:
public function getThemeDefaultBlockTemplates() { return array( 'file' => 'with_icon.php' ); }
That does make sense, due the two different ways that block templates can be provides.
I think the doco here isn't quite correct then:
https://www.concrete5.org/documentation/developers/5.7/working-with-...
What about non-packaged themes? Should this same approach work with a theme that resides in the application/themes folder? I can't seem to get it to work.
I have the file...
/application/themes/my_theme/blocks/youtube/templates/responsive_youtube_video.php
And I have the following in my page-theme.php...
However, when I add a YouTube block, my template is not used. What am I doing wrong?
-Steve
I have the file...
/application/themes/my_theme/blocks/youtube/templates/responsive_youtube_video.php
And I have the following in my page-theme.php...
public function getThemeDefaultBlockTemplates() { return array( 'youtube' => 'responsive_youtube_video.php' ); }
However, when I add a YouTube block, my template is not used. What am I doing wrong?
-Steve
I haven't tried it outside of a package but my assumption would be that it should work.
I can only suggest reinstalling the theme if you haven't done that already (in addition to the cache clearing ritual).
I can only suggest reinstalling the theme if you haven't done that already (in addition to the cache clearing ritual).
> I can only suggest reinstalling the theme if you haven't done that
> already (in addition to the cache clearing ritual).
Yeah, I've done both those things to no avail. Oh well...
-Steve
> already (in addition to the cache clearing ritual).
Yeah, I've done both those things to no avail. Oh well...
-Steve
Turns out it looks for the template in...
/application/blocks/youtube/templates/responsive_youtube_video.php
...which makes no sense to me. I mean, the function is in a page_theme.php file of a specific theme. Why would it look at the application level instead of the theme? Argh...
:-/
-Steve
/application/blocks/youtube/templates/responsive_youtube_video.php
...which makes no sense to me. I mean, the function is in a page_theme.php file of a specific theme. Why would it look at the application level instead of the theme? Argh...
:-/
-Steve
Ah glad you got it sorted. I didn't register that you had your blocks in the theme folder.
Reason being Themes themselves don't have their own Blocks (as you have discovered), but a Package can contain Blocks and Themes.
Reason being Themes themselves don't have their own Blocks (as you have discovered), but a Package can contain Blocks and Themes.
Yeah, I misunderstood the docs referenced in this thread. I thought "enterprise" was the name of the package's theme directory. Actually, I guess it's both the package name and theme name. I know that blocks can't go in a theme directory, but I thought the docs were saying that block TEMPLATES could (which made sense to me since themes are basically collections of page templates).
I think I got it now. Thanks.
-Steve
I think I got it now. Thanks.
-Steve