How to get images path from Blocks?

Permalink
Hi

I have a question regarding placing images folder in a block type directory. My structure is like this:
application
 - custom_block
   controller.php
   view.php
   add.php
   edit.php
   - images
     file1.jpg
     file2.jpg


How do I create the URL from the `view.php` to display the files under `images` folder? I have tried looking everywhere but couldn't find any solution regarding this.

I also learned about BlockView::getBlockUrl() method but don't know how to use it.

I'm using 5.7

BreakfastStudio
View Replies:
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi BreakfastStudio,

There are a few approaches you could use.

1. get the relative path to the block folder
$urlHelper = Core::make('helper/concrete/urls');
$blockType = BlockType::getByHandle('your_block_handle');
$localPath = $urlHelper->getBlockTypeAssetsURL($blockType);

Example: $localPath
/concrete5/application/blocks/your_block_handle
/concrete5/packages/your_package/blocks/your_block_handle
2. use the DIR_REL constant to get the relative URL of the concrete5 install directory
3. use the __DIR__ constant to get the absolute URL for the directory of the file where __DIR__ is used
4. use the DIR_APPLICATION constant to get the absolute URL of the application directory