need help with url helper!
Permalink
Hey,
Just trying to reference some files inside my package folder and want to do it properly by using the Concrete URL Helper.
I tried a couple of ideas but keep getting different errors. Can someone post the code I need to get the folder url for a file like this:
/packages/packagename/foldername/filename.php
Thanks,
Phil
Just trying to reference some files inside my package folder and want to do it properly by using the Concrete URL Helper.
I tried a couple of ideas but keep getting different errors. Can someone post the code I need to get the folder url for a file like this:
/packages/packagename/foldername/filename.php
Thanks,
Phil
That's actually what I had been using up until this point. I thought that there would have been a better way, something that would involve loading the Concrete URL Helper and then using the "getPackageURL" command?
There are better ways to access that if you're working within the concrete framework. Like if you were trying to include a class that was in your packages libraries folder you'd use:
But outside of the framework you're well... outside the framework.
<? Loader::library('filename','packagehandle'); ?>
But outside of the framework you're well... outside the framework.
This doesn't answer your question exactly, but in case someone is looking for this in the future...
If you want to access files in a block that's in your package, you can do it the same way as you would any block. From view.php (or add.php/edit.php) like so:
or from controller.php like this:
If you want to access files in a block that's in your package, you can do it the same way as you would any block. From view.php (or add.php/edit.php) like so:
$this->getBlockURL();
or from controller.php like this:
$bv = new BlockView(); $bv->setBlockObject($this->getBlockObject()); $bv->getBlockURL();
Is there some code I can run from the controller to get this URL?
I am attempting to override some css from my package,
Do I need to hardcode it?
$pkgUrl = "/root/packages/etc"
or can I use a helper to achieve this location from within my controller
$this->addHeaderItem($html->css($pkgUrl.'custom.search.css'));
I am attempting to override some css from my package,
Do I need to hardcode it?
$pkgUrl = "/root/packages/etc"
or can I use a helper to achieve this location from within my controller
$this->addHeaderItem($html->css($pkgUrl.'custom.search.css'));
Just to pull an url for a package, without doing anything with it, first call the helper:
Depending on whether you need an absolute path to the package dir or a relative path to a specific tools folder within the package, one of the next two methods ought to help.
1) Absolute
If working from within a package generated page, using the packageHandle with the following will give an absolute url:
You can still use getPackageURL from without by pulling the packageHandle first with:
2) Relative
To get specific, though, like a css folder, provide the packageName and tools directory (css, elements, or whatever) with the following:
The above will also pull default named tools if the packageHandle is omitted.
(Includes)
Assuming an include is what's desired (it's not really clear, so if it's an url for a link, then not so much) -
This may work from within the controller, but my preference would be to place it inside the view, as CSS is more a display than logic issue; passing a switch down from the controller (or maybe basing the override on the passed view) would isolate layout issues within the view.
or
- then, for css specifically, TheRealSean, follow it up with
hoping that
already precedes the rest.
Just in case, this works for the following as well:
and this may be a little closer to the needs of TorchMedia, to just load up some html with placeholders for some passed vars:
btw, thanks, jordanlev; ended up using that snippet, with the following modification, to make use of an external block from a number of locations:
Hope this helps!
$uh = Loader::helper('concrete/urls');
Depending on whether you need an absolute path to the package dir or a relative path to a specific tools folder within the package, one of the next two methods ought to help.
1) Absolute
If working from within a package generated page, using the packageHandle with the following will give an absolute url:
$pkg = $c->getPackageHandle(); $pkgUrl = $uh->getPackageURL($pkg); // returnshttp://www.mysite.com/packages/myPackage...
You can still use getPackageURL from without by pulling the packageHandle first with:
$pkgHandle = 'myPackage'; $pkg = Package::getByHandle($pkgHandle);
2) Relative
To get specific, though, like a css folder, provide the packageName and tools directory (css, elements, or whatever) with the following:
$pkgHandle = 'myPackage'; $tool = 'css'; $pkgUrl = $uh->getToolsURL($tool, $pkgHandle); // returns /index.php/tools/packages/myPackage/css
The above will also pull default named tools if the packageHandle is omitted.
(Includes)
Assuming an include is what's desired (it's not really clear, so if it's an url for a link, then not so much) -
This may work from within the controller, but my preference would be to place it inside the view, as CSS is more a display than logic issue; passing a switch down from the controller (or maybe basing the override on the passed view) would isolate layout issues within the view.
if($this->controller->getTask() == 'myAction')//right out of the url, like mysite.com/mypage/myAction
or
if($this->myVar == 'myAction')//set in the controller according to taste
- then, for css specifically, TheRealSean, follow it up with
$this->addHeaderItem($html->css($cssFileWithExtension, $pkgName));
hoping that
$html = Loader::helper('html');
already precedes the rest.
Just in case, this works for the following as well:
$this->addHeaderItem($html->javascript($jsFileWithExtension, $pkgName));
and this may be a little closer to the needs of TorchMedia, to just load up some html with placeholders for some passed vars:
$args = array('namedVarInElementFile1' => $namedVarValue1, 'namedVarInElementFile2' => $namedVarValue2) Loader::packageElement($elementFileWithNoExtension, $pkgName, $args); // includes and outputs immediately, subbing named values for $namedVarValue1 and $namedVarValue2 in the element
btw, thanks, jordanlev; ended up using that snippet, with the following modification, to make use of an external block from a number of locations:
$myBlockHandle = 'myBlock' $bv->setBlockOject(BlockType::getByHandle($this->$myBlockHandle));
Hope this helps!
If I could kiss you ;)
That is exactly what I was after thanks for this I was not aware the packages had a class similar to the blocks/pages although I should have taken a look in the core.
This helps a lot though thank you
That is exactly what I was after thanks for this I was not aware the packages had a class similar to the blocks/pages although I should have taken a look in the core.
This helps a lot though thank you
Glad to be of service!
You'll see that the (css and js) helpers will accept a package name in
as well as the loader, in the case of your own homebrewed helper in
as in the case of
Just make sure to name your class appropriately.
Then call them from wherever like:
Here's a helpful link for overrides:
www.www.concrete5.org/documentation/how-tos/developers/change-things...
Cheers!
You'll see that the (css and js) helpers will accept a package name in
concrete/helpers/html.php
as well as the loader, in the case of your own homebrewed helper in
concrete/libraries/loader.php
as in the case of
$myHelper = Loader::helper('myHelp', 'myPackage'); // loads an instance from packages/myPackage/helpers/myHelp.php
Just make sure to name your class appropriately.
class MyPackageMyHelpHelper{ public function myFunction($args){ //act upon $args return $result; } //custom functions }
Then call them from wherever like:
$result = $myHelper->myFunction($args);
Here's a helpful link for overrides:
www.www.concrete5.org/documentation/how-tos/developers/change-things...
Cheers!
If you just want to link to that page use:
<?=DIR_REL?>/packages/packagename/foldername/filename.php
What are you trying to accomplish with this file, usually either tools or single pages will handle all the one-off type stuff.