How to write custom templates with additional resource files

Permalink
Hi guys,

I don't remember reading anything about this in the documentation, but I just figured this out today.

I was creating a custom template for the Image block called "Page Header". I needed a way to have some supporting files available.

My first try was to put them inside blocks/image/assets/ and to refer to them using $this -> getBlockURL () like I would in a custom block, but unfortunately it did not work. My second try was to put them inside blocks/image/templates/assets/ and to refer to them using $bvt -> getBaseURL (), which actually worked fine, except for one problem: "Assets" appeared on the list of custom templates.

Both a little perplexed and frustrated that my assets folder would appear on the list of custom templates (not being a PHP file, after all) I decided to try placing my entire template inside its own directory.

I'm sure others will not be surprised by my saying so, but it was a nice find for me. I thought the only way to create my Page Header template was to keep it all in page_header.php

Instead of using page_header.php, I created a folder called page_header and renamed my PHP file to view.php. I placed the assets folder inside, adopted getBaseURL for referencing them and I was good to go.

Hope this might help someone

elyon