• Resolved rphillips2020

    (@rphillips2020)


    Hi,

    I am trying to write my first plugin and I have hit an issue with moving the template to my plugin.

    I have successfully changed the template path to my plugin, but the associated Block CSS file doesn’t load. On inspecting the code, I get this as a link to the stylesheet –

    ` <link rel=”stylesheet” id=”block-lab__block-ent-details-css” href=”https://www.newleioc.dev.ccwp-contentpluginsleioc-events-templates/blocks/ent-details/block.css?ver=0.0.2&#8243; type=”text/css” media=”all”>

    When I add the missing slashes it works fine. Is there something I am missing or is this a bug in the system?

    Thanks
    PS I love Block Labs plugin, it really helps

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Ryan Kienstra

    (@ryankienstra)

    Hi @rphillips2020,
    Thanks a lot for using Block Lab, and sorry for the delay.

    I have successfully changed the template path to my plugin, but the associated Block CSS file doesn’t load.

    Is that by using the filter block_lab_template_path ? https://github.com/getblocklab/block-lab/blob/9daea7770c439fdc04437f870f9d8d5e521fbccc/php/class-util.php#L106

    Thread Starter rphillips2020

    (@rphillips2020)

    Hi,

    Sorry for the delay in getting back. Yes, I am using this code –

    `add_filter( ‘block_lab_template_path’, function( $path ) {
    unset( $path );
    return __DIR__;
    } );

    I found it online and it works to move the template to my plugin, but the block.css file is not found. On inspection, it seems to be missing the slashes out of the CSS link.

    https://www.newleioc.dev.ccwp-contentpluginsleioc-events-templates/blocks/ent-details/block.css?ver=0.0.2

    Any help will be gratefully received.
    Thanks

    Plugin Author Ryan Kienstra

    (@ryankienstra)

    Hi @rphillips2020,
    Sorry for the delay.

    Your use of the filter looks right.

    1. Does the block.css file load when the filter isn’t used? (it’ll look for it in the theme)

    2. Does replacing return __DIR__; with return dirname( __FILE__ ); help?

    If Xdebug is enabled, it be really helpful if you’d be able to find the value of __DIR__ inside that filter.

    Or maybe with:

    
    add_filter( 'block_lab_template_path',
    	function( $path ) {
    		unset( $path );
    		var_dump( __DIR__ );
    	}
    );
    

    Thanks, and sorry for the delay.

    Thread Starter rphillips2020

    (@rphillips2020)

    Hi

    I got the var_dump from the filter, this what it gave me –

    C:\Users\Roger\Sites\www.newleioc.dev.cc\wp-content\plugins\leioc-events-templates\leioc-events-templates.php:70:string 'C:\Users\Roger\Sites\www.newleioc.dev.cc\wp-content\plugins\leioc-events-templates' (length=82)

    It shows the correct file path to my plugin.

    When I remove the filter and add the block to my Theme folder it finds the Block.Css file correctly.

    I am happy to enqueue the Block CSS file, but I wasn’t sure if this was correct behaviour from the Block Lab plugin. Thanks for your time with this

    Plugin Author Ryan Kienstra

    (@ryankienstra)

    Hi @rphillips2020,
    Thanks for pasting the var_dump.

    Sorry, I don’t know why the stylesheet href is printed as https://www.newleioc.dev.ccwp-contentpluginsleioc-events-templates/blocks/ent-details/block.css?ver=0.0.2&#8243

    It might have something to do with the backslashes in the __DIR__, as opposed to forward slashes in a Unix environment.

    Sorry I can’t be more helpful, and thanks a lot for using Block Lab.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Block CSS not working when moved template path’ is closed to new replies.