Theme path from a block view?

Permalink 4 users found helpful
I'm not sure I'm thinking about this correctly, but is it possible to get the theme path from a Block view?

I have created my own Block, but I can't seem to figure out how to get to any assets within the current theme's directory.

 
RadiantWeb replied on at Permalink Reply
RadiantWeb
$uh = Loader::helper('concrete/urls');
$bt = BlockType::getByHandle('your_block');
$local = $uh->getBlockTypeAssetsURL($bt)';


that's just for the block root.

if you want to add subfolder location info from your block, simply concatenate directory info:

$local = $uh->getBlockTypeAssetsURL($bt).'sub_folder/file.fl'
RadiantWeb replied on at Permalink Reply
RadiantWeb
I'm an idiot. to early.lol you want the Theme path from a block view.

you should be able to call the theme path as normal from the controller, and then grab it from your block view.
$thempath = $controller->getTheme();
echo $themepath;

and then in your controller:
function getTheme(){
     $theme = $this->getThemePath();
     return $theme;
}
inertia replied on at Permalink Reply
Ahhhh... okay. That's what I was doing wrong. I was trying to call the getThemePath method on the Block's view.

What's strange is that it didn't throw an exception or an error, it just produced nothing.

So getThemePath is a method of the controller?
jbx replied on at Permalink Reply
jbx
getThemePath is a function from the view object. View::getThemePath(); should work, but doesn't seem to work from within block views. Seems to me like the block views aren't theme aware which is kinda odd...

I tried it in the controller, but just got an error because the method isn't available from within the controller - only the view...

Anyone know a way around this?

Jon
jbx replied on at Permalink Reply
jbx
getThemePath is a function from the view object. View::getThemePath(); should work, but doesn't seem to work from within block views. Seems to me like the block views aren't theme aware which is kinda odd...

I tried it in the controller, but just got an error because the method isn't available from within the controller - only the view...

Anyone know a way around this?

Jon
jbx replied on at Permalink Best Answer Reply
jbx
$v = View::getInstance();
$v->getThemePath();

That'll work...

:)
RadiantWeb replied on at Permalink Reply
RadiantWeb
good call.

my bad.

thanks for sharing!
inertia replied on at Permalink Reply
Not to get hung up on design patterns or anything... but is there a reason for not having the themepath directly accessible within the Block view?

Is it considered "bad form" to have Block assets stored within a theme?

My original reason for wanting this method was because I didn't know the best place to store an image element that I'm using in my Block (just a button skin actually).

Thanks for all the great help!