Foxy Forum Status

We're no longer responding to questions via our forum, but we will keep it up for historical reasons. If you can't find the answer you're looking for, please visit our knowledge base or contact us. If there's enough interest in the future, we may bring the forum back.

Overriding Twig templates and twig.js

freshjonesfreshjones Member
in Help edited January 2017
I would like the checkout carts shipping_and_handling label to always say "Shipping & Handling"

I noticed the label is refreshed via twig.js to reflect the specific shipping method I have chosen.

I can override the server-side order_totals block to comment out the part that does this like so:

{% set shipping_service_label = config.lang.cart_shipping_and_handling|raw %}
{# note: we just want this to stay the same as above
{% if shipping_address.shipping_service_id != 0 and shipping_address.shipping_service_description %}
{% set shipping_service_label = shipping_address.shipping_service_description %}
{% endif %}

But twig.js just takes over anyway and changes it dynamically. Can you tell me how best to either override the twig statement that does this, or modify the twig.js template that is causing this to happen?

thanks very much for any help here.
  • it looks like twig.js rerenders the "cart" template in this instance and for some reason that template in the javascript file does not get updated with the changes I override.

    there is another twig.js template on the page with the ID twig({id:"" which does have the edits to the template that I have made, but that template is not called by twig.js

    perhaps the best way to get this to work is to tell twig.js to call instead of just cart? how would I go about doing that?

  • ok I got it to work by doing this in a custom js file

    (function (FC) {
    FC.cart.renderOrderTotals = function ()
    FC.Template('checkout').renderBlock('[data-fc-id="block-order-totals"]', 'order_totals');

    could you let me know if this is the correct way to do this? and also if its safe to do this without running FC.onload or listening for ready.done.

  • fc_adamfc_adam FoxyCart Team

    Could you confirm the store this is for so we could take a look? Any modifications to the cart include template should flow on to the cart, checkout and receipt automatically - you shouldn't need to do anything else there.
  • fc_adamfc_adam FoxyCart Team

    Thanks for whispering the details - I can see what you're trying to do now. That's a solid work-around for now on your checkout template. I'll open a ticket on our side to see if that's something we can fix natively as well. It does get complex when you have an embed within an embed, but we'll take a look.

    Another option you could take would be to override the cart include template directly - updating the order_totals block to have a conditional to check if the context is the checkout or not, and customise accordingly:

    {% block order_totals %}
    {% if context == "checkout" %}
    {% else %}
    {% endif %}
    {% endblock %}
    That would remove the need for the custom JS replacement here.
  • Thanks adam,

    I totally missed the fact that I can override the cart include template through the admin interface!

    I'm sure that will solve the issue.

    I was assuming that the only way to modify the cart template was via the checkout template but now I see what I was missing.

Sign In or Register to comment.