How can I bust a template cached plugin variable in a loop? 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.
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.)