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:
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?

mesuva
 
goodnightfirefly replied on at Permalink Best Answer Reply
goodnightfirefly
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.


'file' => 'with_icon'
is looking for 'templates/with_icon/view.php'


'file' => 'with_icon.php'
is looking for 'templates/with_icon.php'
mesuva replied on at Permalink Reply
mesuva
That was it! Thanks!

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-...
Shotster replied on at Permalink Reply
Shotster
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...

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
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
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).
Shotster replied on at Permalink Reply
Shotster
> 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
Shotster replied on at Permalink Reply
Shotster
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
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
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.
Shotster replied on at Permalink Reply
Shotster
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