getThemePath() in block template
Permalink
I've tried a couple times to use the getThemePath() in a block template file, In the example below I was expecting the file name with full path to be returned, getThemePath() does not return anything, I just get /images/filename
what am I doing wrong?
Thanks
what am I doing wrong?
echo('<a href="' . $pageLink . '"><img src="' . $this->getThemePath() .'/images/'. $ni->getName() .'_menu.png"></a>');
Thanks
try to grab the Instance of the current view first, if you really want to access the current path to the theme, not the path to the block you're using by:
I'm not getting that to work, can you give me an example how to insert that into the path for a file in the theme image directory?
Thanks
Thanks
Try doing this
And use $themePath instead.
$v = View::getInstance(); $themePath = $v->getThemePath();
And use $themePath instead.
That looks like the solution. Thanks a lot!
Brilliant! That's exactly what I was looking for too. Thanks Andrew.
[edit] Oops. Spoke too soon. Following is my template code:
The point is to insert a logo into the top-left corner of the content box and then apply some other sytling to the box. Everything works except for the image. Most of the time the path comes out as "/images/oriana_logo_blah-blah-blah" without the proper theme path in front of it. Strange thing is, every now and again, the theme path DOES work. Can't figure that one out. Anyway, just need to get the IMG fixed and I'll be happy.
Cheers.
[edit 2] Threw in the "echo $themePath" line as a troubleshooting tool. It outputs "Theme Path: <blank space>" the majority of the time.
[edit] Oops. Spoke too soon. Following is my template code:
<?php defined('C5_EXECUTE') or die("Access Denied."); ?> <div class="content_breakout_template"> <?php $v = View::getInstance(); $themePath = $v->getThemePath(); ?> <img class="o-logo" src="<?=$themePath?>/images/oriana_logo_35x35_trans-back.png" /> <?php $content = $controller->getContent(); print $content; echo "Theme Path: ".$themePath; ?> </div> <!-- Close breakout_shadow_centred -->
The point is to insert a logo into the top-left corner of the content box and then apply some other sytling to the box. Everything works except for the image. Most of the time the path comes out as "/images/oriana_logo_blah-blah-blah" without the proper theme path in front of it. Strange thing is, every now and again, the theme path DOES work. Can't figure that one out. Anyway, just need to get the IMG fixed and I'll be happy.
Cheers.
[edit 2] Threw in the "echo $themePath" line as a troubleshooting tool. It outputs "Theme Path: <blank space>" the majority of the time.
Try This:
<?php $v = View::getInstance(); $themePath = $v->getThemePath(); echo "<img class=\"o-logo\" src=\"$themePath/images/oriana_logo_35x35_trans-back.png\" />"; ?>
Hi Hugo,
Thanks for the suggestion, but as far as I can see it's exactly the same as what I've done outside of forcing all of the code to be inside a single PHP code block instead of mixing the PHP/HTML. I understand your thinking but that's also why I used the last block as a sanity check --> echo "Theme Path: ".$themePath. The result is the same.
Thanks for the suggestion, but as far as I can see it's exactly the same as what I've done outside of forcing all of the code to be inside a single PHP code block instead of mixing the PHP/HTML. I understand your thinking but that's also why I used the last block as a sanity check --> echo "Theme Path: ".$themePath. The result is the same.
It's possible that the view hasn't been loaded yet at the time you're calling it.
Question for you: is this a custom template for the block's view, or are you trying to do this in the add/edit form?
Question for you: is this a custom template for the block's view, or are you trying to do this in the add/edit form?
And another thought -- if this is a block, you probably shouldn't be referring to assets in the theme anyway, because a block should work independently from a theme (that is, it should work for any and all themes, regardless of which one is installed).
So what you might want to do instead is include the image in the block's directory (or the custom template's directory if that's what you're doing). Then you can get THAT path using this code:
So what you might want to do instead is include the image in the block's directory (or the custom template's directory if that's what you're doing). Then you can get THAT path using this code:
<img class="o-logo" src="<?php echo $this->getBlockURL(); ?>/images/oriana_logo_35x35_trans-back.png" />
This is exactly what is needed in most cases, however, when you create a custom block template, this path changes and since you do not want to modify a block package for example, is there another method for calling the custom block template path?
From
/package/block_name/templates/template_name/view.php
to
/blocks/block_name/templates/template_name/view.php
From
/package/block_name/templates/template_name/view.php
to
/blocks/block_name/templates/template_name/view.php
Hi,
I'm creating a package with a custom template of page_list inside. Whan i'm in the view.php of my custom template i can't get the url ou relative path to this directory (from my package) is right?
Thanks a lot a lot
Seb
I'm creating a package with a custom template of page_list inside. Whan i'm in the view.php of my custom template i can't get the url ou relative path to this directory (from my package) is right?
Thanks a lot a lot
Seb