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

bobrocke
 
bbeng89 replied on at Permalink Reply
bbeng89
Unfortunately I don't believe blocks can have helpers. If you look at this how-to:http://www.concrete5.org/documentation/how-tos/developers/understan... you'll see that besides templates, the only directory blocks can have is a tools directory. You can find more info about block tools at the bottom of this page:http://www.concrete5.org/documentation/developers/blocks/directory-...

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.
bobrocke replied on at Permalink Reply
bobrocke
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.
bbeng89 replied on at Permalink Best Answer Reply
bbeng89
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.
bbeng89 replied on at Permalink Reply
bbeng89
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:
$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!
JohntheFish replied on at Permalink Reply
JohntheFish
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.