Documentation You are here: start » v » 2.0 » template_sets

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Last revisionBoth sides next revision
v:2.0:template_sets [2017/07/20 07:27] – [Adding a Template Set] adamv:2.0:template_sets [2018/10/12 08:21] – [As part of a language/currency selector] adam
Line 60: Line 60:
 </code> </code>
  
-With using straight HTML like that - the links will trigger the cart to show. If you want to perform the template set change in the background, you can perform a [[v:2.0:json|JSONP]] cart request in the background based on that selection to switch the cart's template set for the customers session+With using straight HTML like that - the links will trigger the cart to show. If you want to perform the template set change in the background, you can perform a [[v:2.0:json|JSONP]] cart request in the background based on that selection to switch the cart's template set for the customers session. Include this code on your website with your existing javascript (for example, right before the closing ''</body>'' tag:
  
 <code javascript> <code javascript>
Line 75: Line 75:
 </code> </code>
  
 +==== On page load (if it's not already set) ====
 +
 +If you have separate websites, where each site matches a different template set, you can also use javascript to dynamically set the respective template set on page load. This removes the need for the customer to select the language, and just automatically sets it if it's not already set. You would include this code as part of your website template with your other javascript, right before the closing ''</body>'' tag:
 +
 +<code javascript>
 +<script>
 +var FC = FC || {};
 +FC.onLoad = function() {
 +    FC.client.on("ready.done", function() {
 +        var template_set = "my-template-set";
 +
 +        var existing_template_set = (FC.json.template_set == "") ? "DEFAULT" : FC.json.template_set;
 +        if (existing_template_set != template_set) {
 +            FC.client.request('https://' + FC.settings.storedomain + '/cart?template_set=' + template_set);
 +        }
 +    }
 +};
 +</script>
 +</code>
 +
 +Within that code you will need to update the ''my-template-set'' string to match the template set code that you want that particular page to use.
 ===== Determining the current template set ===== ===== Determining the current template set =====
  
 The cart's current template set is available within the cart JSON object, as ''FC.json.template_set'' in javascript, and ''%%{{%% template_set %%}}%%'' in Twig. The cart's current template set is available within the cart JSON object, as ''FC.json.template_set'' in javascript, and ''%%{{%% template_set %%}}%%'' in Twig.

Site Tools