In my base template i set some variables like currency , currency symbol based on the IP address detected. This is done from a geolocation plugin which caches the result (ip,currency, currency symbol,lang) and makes them available to the template as {{craft.geo.info.currency}}

The problem:

Our site is in UK When a visitor from overseas eg. USA comes they get dollar prices and conversions etc

However, in the product list template I am caching the entry loop with cache tags and rendering the currency symbol with the plugins global template variable like this:

{{ craft.geo.info.currency_symbol |raw}} price XX

USA ip addresses sees US dollars - great!

However in the UK view of product list, and within the product page template loop, we suddenly see the dollar symbol too.

In my footer i spit out the {{craft.geo.info.currency_symbol}} with no cache tags and I get UK GBP currency as I expect.

I guess Craft/Twig is just showing the template cache regardless of plugin variable?

Is there a way around this?

My solution for now is to remove the cache tags from the product list - its not that many products and performance is still good - but I'd like to know how to combine the plugin currency symbol variable within the cached loop.

1 Answer 1


Left to itself, the {% cache %} tag will cache the content per-url. The problem you have is that the same url sometimes has $'s, and sometimes has GBP.

You can use the using key feature to cache based on the url and the currency:

{% cache globally using key craft.request.path ~ craft.geo.info.currency_symbol %}

(craft.geo.info.currency_symbol may not be the best disambiguator string, but this should get you started.)

  • My currency symbol is not in the url - are you suggesting nesting a global cache call for each url within the entry loop cache? I think i am missing something in how this might solve the issue.
    – joomkit
    Commented Sep 4, 2016 at 18:41
  • You cache on a key that contains both the url and the currency symbol. So when two people hit the same url and are using the same currency symbol, they get the same cache entry, but when two people hit the same url using different currency symbols, they get different cache entries. ~ is the string concatination operator. Commented Sep 4, 2016 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.