2

I'm using getURL() as follows in my Craft template:

{% set sharingImageURL = entry.sharingImage[0].getUrl('socialMedia') %} 

Every time the output is a root relative URL and I'd like it to be a complete URL (including http://www.mydomain.com).

I can't figure out how to make that work. Can I do it with getURL() or is there a different method I should be using? Would appreciate some guidance!

Thanks.

Brad Bell
  • 67,440
  • 6
  • 73
  • 143
dpayne
  • 659
  • 6
  • 14

1 Answers1

3

Craft should actually output absolute URLs when using getUrl. But you need to set siteUrl to make this work, so check if you have it set in Settings → General or with a siteUrl property in your general.php config file.

carlcs
  • 36,220
  • 5
  • 62
  • 139
  • Thanks! My issue is that changing the siteUrl has the potential to create a variety of other issues across the site and I only want this particular rule to output the complete URL. Is there a different way that I can get http://'www.mydomain.com/ to show up in front of the root relative output of my getURL? Maybe by adding some fixed text in front of the rule in some way? Any additional guidance would be much appreciated! – dpayne May 26 '15 at 17:35
  • Sure, but I would highly recommend to refactor all the code and set siteUrl to your actual domain. Probably not that much work! Anyways, you could always prepend any text with twig like so: {% set sharingImageURL = 'http://example.com' ~ entry.sharingImage[0].getUrl('socialMedia') %}. – carlcs May 26 '15 at 17:40