Getting Helpers (etc.) From Inside Blocks Inside Packages?
Permalink
There are a number of functions that use a $pkgHandle parameter to load stuff from within packages, such as getToolsURL() and Loader::helper().
How would you load a helper, or tool, or whatever from within a block inside a package? For example, from here:
packages/my_package/blocks/my_block/helpers
How would you load a helper, or tool, or whatever from within a block inside a package? For example, from here:
packages/my_package/blocks/my_block/helpers
OK. So how about the getToolsURL() function? How do I point that into a block with a package? It seems to only want a $pkgHandle parameter - nothing about a block.
You'll want to use the getBlockTypeToolsURL() function. It takes a block type variable as a parameter. Check out my comment below for some more info and an example.
Also, to better answer your question, you can load a script in the tools directory by using the getBlockTypeToolsURL() function. From the example in that link I sent you, the Page List block uses the following code to generate the RSS URL:
So you can see the block type is assigned to the variable $bt then passed to getBlockTypeToolsURL.
Hope that helps!
$btID = $b->getBlockTypeID(); $bt = BlockType::getByID($btID); $c = $rssb->getBlockCollectionObject(); $a = $rssb->getBlockAreaObject(); if (is_object($a)) { $rssUrl = $uh->getBlockTypeToolsURL($bt)."/" . $tool . "?bID=".$rssb->getBlockID()."&cID=".$c->getCollectionID()."&arHandle=" . $a->getAreaHandle(); return $rssUrl; }
So you can see the block type is assigned to the variable $bt then passed to getBlockTypeToolsURL.
Hope that helps!
Just a footnote to the excellent comments above. While blocks can't have their own exclusive helpers, blocks can live in a package that also provides helpers.
So if the tools directory won't work for you then I think your only option might be to put your helper outside the block in the package-level helper folder.