@g2lyon Thanks for posting. I’m just trying this out, and can’t seem to replicate the problem myself (loading blocks from a plugin instead of a theme, by altering the template path with the block_lab_template_path
filter).
Could you post the code you’re using to filter the template path? Also, could you post a screenshot of your plugin’s directory structure with the block templates and stylesheets?
Hello Luke,
Thanks for prompt answer,
QUESTION 1:
function url_templates_blocklab(){
return ABSPATH.'wp-content\plugins\myplugin';
add_filter('block_lab_template_path','url_templates_blocklab' );
I think the filter is good because the blocks are displayed, but without styling from css files.
If I add some style in the block.php file it works
QUESTION 2:
Structure is as follows:
mychildtheme
blocks
myblock
block.css
block.php
preview.php
myotherblock
etc… IT WORKS!(block displayed with styling)
Then I moved to:
myplugin
blocks
myblock
block.css
block.css
preview.php
myotherblock
etc… IT DOES NOT (block displayed, but without styling)
Sorry, its quite late here, so dont expect some new post from my side before tomorow morning!
Thanks in advance for your help
Sorry, new styling, easier to read
mychildtheme
blocks
myblock
block.css
block.php
preview.php
myotherblock
etc… IT WORKS!(block displayed with styling)
Then I moved to:
myplugin
blocks
myblock
block.css
block.php
preview.php
myotherblock
etc… IT DOES NOT (block displayed, but without styling)
Some more tests:
Instead of moving the complete blocks directory from mytheme to myplugin I moved only the block.php and preview.php files.
The bolck.css files are remaining in mytheme
Then I applied the filter.
IT WORKS!!
My conclusion is that, even if you add filter, Block Lab does not look for css files in plugin, but only in theme.
I would prefer the complete set (templates+css) to stay together in the same place. For me block css belongs to the block design, not to site design. It works in this way for example in Drupal.
May be one more filter should be added? add_filter(‘block_lab_css_path’,’url_css_blocklab’ );
@g2lyon Thanks for this extra info. It helped me figure out that – you’re right – there is a bug happening here.
There’s a fix in the works over here, which I’m hoping to look more closely at today or tomorrow. If you get a chance, could you test it out?
https://github.com/getblocklab/block-lab/pull/470
@g2lyon uh-huh! I figured it out!
The slashes you’ve included in the filter URL are the wrong type.
Try changing:
return ABSPATH.'wp-content\plugins\myplugin';
to:
return ABSPATH.'wp-content/plugins/myplugin';
Hello Luke,
It works! Thanks,
Anti slashes were coming from a copy/paste in the file property window.
Unfortunately I have to work on W10. This wouldn’t happen in Linux!.
Slashes vs anti slashes / Linux vs Windows
I guess I will not be the only one doing this mistake.
But something remains unexplained for me: Why was it working with block.php files and not with block.css files?
Because the PHP files can be included from the server root path (i.e. /app/server/public_html/wp-content/plugins/myplugin/blocks/block.php
), but the CSS needs to be enqueued from a URL (i.e. https://example.com/wp-content/plugins/myplugin/blocks/block.css
).