XF 2.0 External data path in templates

mjda

Well-known member
Is it possible to get the external data path in a template? Right now I'm using <img src="data/scu/featuredthreads/... but I'd like to use something like <img src="{$dataPath}/scu/featuredthreads/.... Is this possible?
 
Solution
Generally you'd achieve this with a method on the entity you're working with (and you'd want to use the external data URL, not the path):

PHP:
public function getThingUrl(bool $canonical = false): string
{
    return $this->app()->applyExternalDataUrl('your/thing.jpg', $canonical);
}
Generally you'd achieve this with a method on the entity you're working with (and you'd want to use the external data URL, not the path):

PHP:
public function getThingUrl(bool $canonical = false): string
{
    return $this->app()->applyExternalDataUrl('your/thing.jpg', $canonical);
}
 
Solution
Generally you'd achieve this with a method on the entity you're working with (and you'd want to use the external data URL, not the path):

PHP:
public function getThingUrl(bool $canonical = false): string
{
    return $this->app()->applyExternalDataUrl('your/thing.jpg', $canonical);
}
Awesome, thanks @Jeremy P! I actually gave up on this and manually inserted my URL into the template. That meant, though, that I had to do it for both of my sites and the sites of those others who used the add-on. Good to finally have a solution after 3 years! 🤣

Again, thanks! Much appreciated!
 
I am quite new to this and sorry for the dumb question, but how do I use this in the HTML part of an advertising entry? It says I can use the template syntax and I read through the documentation in the manual but I am not sure what to do with this.

Any idea @mjda or @Jeremy P ?

Thanks
Andreas
 
Once you've added your code into the entity for whatever entity you're dealing with, in the template you would use this:

Code:
$entity.getThingUrl()
 
Back
Top Bottom