Support » Plugin: Block Lab » Custom Template Path

  • Hi,

    I’m trying to customize the default template path for blocks, using the filter block_lab_template_path(), but must be doing something wrong. On the front end it shows the message that template is missing from the default path. This is how I have used the filter:

    function my_block_lab_template_path($template_path) {
    	$template_path = get_stylesheet_directory_uri() . '/resources/views/blocks/';
    	return $template_path;
    }
    add_filter('block_lab_template_path', __NAMESPACE__ .'\my_block_lab_template_path' );
    • This topic was modified 4 months, 2 weeks ago by Tibor Paulsch.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Luke Carbis

    (@lukecarbis)

    Hi Tibor – thanks for reporting this. I’ll take a look as soon as I get a chance. Are you getting the template in the editor?

    Thanks for the quick reply Luke. Editor gives the same ‘Template file /blocks/block-name.php not found’ message.

    Plugin Author Luke Carbis

    (@lukecarbis)

    @tibor I found the problem.

    The template path should be the absolute path to the template, not the URI.

    Also, the template name includes the blocks directory, so your function should leave that out. Additionally, no trailing slash is required.

    
    function my_block_lab_template_path( $template_path ) {
    	return get_stylesheet_directory() . '/resources/views';
    }
    

    Obviously, this wasn’t super clear or well documented, so I’ve created a pull request to add that information, and support a trailing slash if it happens to exist:

    https://github.com/getblocklab/block-lab/pull/358

    • This reply was modified 4 months, 2 weeks ago by Luke Carbis.
    • This reply was modified 4 months, 2 weeks ago by Luke Carbis.
    • This reply was modified 4 months, 2 weeks ago by Luke Carbis.

    Thanks Luke! Makes sense and works like a charm now.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.