Correct way to access images from extension

Discussion forum for Extension Writers regarding Extension Development.
CentaurAtlas
Registered User
Posts: 50
Joined: Sun Dec 02, 2007 5:39 pm
Contact:

Correct way to access images from extension

Post by CentaurAtlas »

Hey,
I am trying to insert an image in the view_body_avatar_after template event. I can insert text there easily, but the images are not showing up. I have tried various URLs with no success:

Code: Select all

<img src="images/example.png">
<img src="./images/example.png">
<img src="/images/example.png">
<img src="url('images/example.png')">
This topic seems close, but not exactly it:
viewtopic.php?f=461&t=2284366&start=15

One extension I've seen (http://www.phpbb3bbcodes.com/viewtopic.php?f=61&t=2575) says to copy the images into the phpbb3 root /images directory. I didn't think that was correct, because I saw this:
https://www.phpbb.com/extensions/writing/
showing images in
/styles/all/theme/images/
as an example. It certainly seems more logical to keep everything together, but the directory structure was an "example."

I have cleared the test board cache, the browser cache (and tried it in 3 different browsers).

I looked at some other plugins and they vary (as above), some showing:

Code: Select all

 url(images/hohohat.png)
(but that is the css file.

Any tips? :-)

I have done plugins for other software (e.g. Wordpress) but not phpbb yet, and was just trying to do a simple one. I've done some other customizing for phpbb over the last 8 years though. Just no extensions and nothing on 3.1.x yet.

Thanks a lot!
User avatar
Lumpy Burgertushie
Registered User
Posts: 68316
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Correct way to access images from extension

Post by Lumpy Burgertushie »

did you try <img src="example.png">
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.3 Styles by PlanetStyles.net

If nobody is in the forest, does a tree really fall?
CentaurAtlas
Registered User
Posts: 50
Joined: Sun Dec 02, 2007 5:39 pm
Contact:

Re: Correct way to access images from extension

Post by CentaurAtlas »

Hey,
That was actually the first one I tried! But neglected to include it in the list! ;-)

Thanks for the suggestion!
CentaurAtlas
Registered User
Posts: 50
Joined: Sun Dec 02, 2007 5:39 pm
Contact:

Re: Correct way to access images from extension

Post by CentaurAtlas »

By the way, if I put it in the root images location, e.g.
phpbb/images

then both work:
<img src="./images/example.png">
<img src="images/example.png">

If I put in the entire path, e.g.:
<img src="./ext/myphpbb/tempevt/styles/all/theme/images/example.png">

It also works. I suppose I will just do that, but I had thought that is should be a relative path with the guidelines.

Thanks again for the suggestion...and if anyone has any others, I'll try them!

:-)
nicofuma
3.2 Release Manager
3.2 Release Manager
Posts: 546
Joined: Sun Apr 13, 2014 1:47 am
Location: Grenoble - France

Re: Correct way to access images from extension

Post by nicofuma »

It should be an absolute path. I think that we will add an helper for that in the future but it need some work and it can't happen before 3.2.
Member of phpBB Development-Team
No Support via PM
User avatar
RMcGirr83
Former Team Member
Posts: 21698
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Correct way to access images from extension

Post by RMcGirr83 »

You can use css to accomplish this without having to use the img src tag.

https://github.com/phpbbmodders/phpbb-3 ... er.php#L98

https://github.com/phpbbmodders/phpbb-3 ... ageset.css
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beerImage
User avatar
Wolfsblvt
Registered User
Posts: 634
Joined: Sun Oct 26, 2014 9:12 pm
Location: Solingen, Germany
Contact:

Re: Correct way to access images from extension

Post by Wolfsblvt »

Otherwise you have to do what nicofuma said, use an absolute path.
You can easily achieve this with default template vars for the paths. I this in everyone of my extensions, even if I don't need them: advancedpolls - listener.php
If you have a specific extension request and you are willing to pay for, you can write me a PM.
My extensions (Trending: @Mention SystemAdvanced PollsUser Online Time)

»Du kamst zu uns. Deine Stimme kam. Du zeigtest uns die Sterne. Sie funkelten. Wir konnten sehen.«
CentaurAtlas
Registered User
Posts: 50
Joined: Sun Dec 02, 2007 5:39 pm
Contact:

Re: Correct way to access images from extension

Post by CentaurAtlas »

Thanks for the replies. The funny thing is, I was just looking at code before I checked here and was looking at how you did it on avatarsonmemberlist - thanks for the reply!

edit:
e.g.

Code: Select all

 <img src="{T_EXT_AVATARSONMEMBERLIST_THEME_PATH}/images/no_avatar.gif" alt="Avatar" />
I am going to try using something similar to that.
User avatar
Wolfsblvt
Registered User
Posts: 634
Joined: Sun Oct 26, 2014 9:12 pm
Location: Solingen, Germany
Contact:

Re: Correct way to access images from extension

Post by Wolfsblvt »

Great (:
I think this is the best solution at the moment. It used absolute paths, but generated from the real current board url, uses php core functions.
If you have a specific extension request and you are willing to pay for, you can write me a PM.
My extensions (Trending: @Mention SystemAdvanced PollsUser Online Time)

»Du kamst zu uns. Deine Stimme kam. Du zeigtest uns die Sterne. Sie funkelten. Wir konnten sehen.«
CentaurAtlas
Registered User
Posts: 50
Joined: Sun Dec 02, 2007 5:39 pm
Contact:

Re: Correct way to access images from extension

Post by CentaurAtlas »

I thought so too. Looking at the code is often worth 1000 words. ;-)
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5284
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: Correct way to access images from extension

Post by MattF »

Wolfsblvt wrote:Great (:
I think this is the best solution at the moment. It used absolute paths, but generated from the real current board url, uses php core functions.
Except what happens when the user's style is some 3rd party style? because it looks like you are using $this->user->style['style_path']
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
Wolfsblvt
Registered User
Posts: 634
Joined: Sun Oct 26, 2014 9:12 pm
Location: Solingen, Germany
Contact:

Re: Correct way to access images from extension

Post by Wolfsblvt »

VSE wrote:Except what happens when the user's style is some 3rd party style? because it looks like you are using $this->user->style['style_path']
In this case it should use the style the user had chosen, shouldn't it?
If you have a specific extension request and you are willing to pay for, you can write me a PM.
My extensions (Trending: @Mention SystemAdvanced PollsUser Online Time)

»Du kamst zu uns. Deine Stimme kam. Du zeigtest uns die Sterne. Sie funkelten. Wir konnten sehen.«
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5284
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: Correct way to access images from extension

Post by MattF »

Wolfsblvt wrote:
VSE wrote:Except what happens when the user's style is some 3rd party style? because it looks like you are using $this->user->style['style_path']
In this case it should use the style the user had chosen, shouldn't it?
Yeah, but what if your extension does not know about the style?

Potentially your code could look for a theme folder in:
./ext/vendor/extension/styles/foobar/theme/

Have you tested what happens in this situation, for what you are doing?
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
Wolfsblvt
Registered User
Posts: 634
Joined: Sun Oct 26, 2014 9:12 pm
Location: Solingen, Germany
Contact:

Re: Correct way to access images from extension

Post by Wolfsblvt »

When user has the style foobar my extension will look in
./ext/vendor/extension/styles/foobar/theme/
yes. That's what it should do, shouldn't it?

Or how would you solve this?
If you have a specific extension request and you are willing to pay for, you can write me a PM.
My extensions (Trending: @Mention SystemAdvanced PollsUser Online Time)

»Du kamst zu uns. Deine Stimme kam. Du zeigtest uns die Sterne. Sie funkelten. Wir konnten sehen.«
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5284
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: Correct way to access images from extension

Post by MattF »

Wolfsblvt wrote:Or how would you solve this?
use the "all" folder and just point directly to that and not use the user style variable.

you're extension can't have a style folder for every single style created for phpBB.
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
Post Reply

Return to “Extension Writers Discussion”