The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Where is the address type passed to address.checkout.inc.twig?

Hi there,

To more easily incorporate some checkout conversion optimizations I have read about I will be making a lot of changes to the checkout template. Presently I am looking at making some changes to the address.checkout.inc.twig template which is called by the checkout template through the following twig line...


{% include "address.checkout.inc.twig" with {'address': shipping_address} %}


I want to incorporate a modified address.checkout.inc.twig template into the checkout template at that place in the code but am wondering how to incorporate the "with..." portion of that twig line into my changes?

In other words I will not need the "include "address.checkout.inc.twig" portion of that twig line but will still need to set the "with {'address': shipping_address}" for my inserted code (unless there is another way to set this value within the address.checkout.inc.twig file more directly).

I have been looking at the code inside the address.checkout.inc.twig template but can't quite yet figure out how that address setting is passed to it or where it is picked up in the code.

Can someone please give me some input on this?

Thanks.

Carlos

Comments
  • fc_adamfc_adam FoxyCart Team
    @carlos123,

    Great question.

    So the with {'address': shipping_address} portion essentially sets a variable for the template include. So that means that there would be a variable called address accessible within the template.

    If you're wanting to edit the address include - you'll want to embed that include directly within the template. To mimic the with you could approach it two ways. Either change any reference to address to shipping_address. Alternatively, you can add {% set address = shipping_address %} before the embedded include.

    Both of those approaches should get it working for you.
  • Thanks Adam! Exactly what I need to know.

    Carlos
  • Adam...

    Is there some way using Twig or other method to include the large amount of twig code as found inside the address.checkout.inc.twig template within the code section below (from the checkout template) WITHOUT having to include it twice?


    {# per Carlos: changed the code inside the block customer_shipping section below. See original code in fc-address.checkout.inc.twig.html
    for differences. #}
    {% block customer_shipping %}
    {% if not has_multiship %}
    {% set address = shipping_address %}
    {% include "address.checkout.inc.twig" %}
    {{ utils.use_different_addresses(use_different_addresses, config.lang) }}
    {% else %}
    {% for multiship in multiship_data %}
    {% set address = multiship %}
    {% include 'address.checkout.inc.twig' %}
    {% if MULTISHIP_PREVIOUSLY_USED_SHIPTOS_EXIST %}
    {# previously used addresses select box #}
    {% endif %}
    {# Subtotal (shipto subtotal + shipping + tax) #}
    {% endfor %}
    {% endif %}
    {% endblock customer_shipping %}


    Notice the "{% set address = shipping_address %}" in two places in the above code? I will be inserting my modified address.checkout.inc.twig code just after that in both places where it says "{% include 'address.checkout.inc.twig' %}" but that's going to make for a VERY long checkout template.

    I could remove the multiship else code entirely (and thus eliminate one of the places where the address.checkout.inc.twig code would need to be inserted) but I am trying to keep whatever default functionality is in place so that I don't have to re-include it again in the future in case the unused functionality is ever needed.

    Any tip on how to avoid the huge insertion of modified code here would be appreciated.

    Thanks.

    Carlos
  • Could I for example just define a block within the checkout template like so...(including the address.checkout.inc.twig code inside that block)?


    {% block address_checkout %}
    {# code inside the address.checkout.inc.twig file goes here #}
    {% endblock address_checkout %}


    A block which I would then call like so...


    {% block customer_shipping %}
    {% if not has_multiship %}
    {% set address = shipping_address %}
    {{ block('address_checkout') }}
    {% include "address.checkout.inc.twig" %}
    {{ utils.use_different_addresses(use_different_addresses, config.lang) }}
    {% else %}
    {% for multiship in multiship_data %}
    {% set address = multiship %}
    {{ block('address_checkout') }}
    {% if MULTISHIP_PREVIOUSLY_USED_SHIPTOS_EXIST %}
    {# previously used addresses select box #}
    {% endif %}
    {# Subtotal (shipto subtotal + shipping + tax) #}
    {% endfor %}
    {% endif %}
    {% endblock customer_shipping %}


    I think that should work. I would still appreciate input on this but I will try the above.

    Carlos
  • Hmm...that's not quite working. I mean it works in one sense...the code does show up on the page but twice. Once inside the regular FoxyCart checkout framework and once where I have defined the new block.

    Carlos
  • fc_adamfc_adam FoxyCart Team
    @carlos123,

    When you define a block within our templates - that block is also output on the page where it's included - which is the duplication you're experiencing. You could try placing the initial block definition where the first instance of that block goes, and then just output that block like {{ block('block-name') }} in the subsequent places.
  • Sounds good Adam. Thanks!

    Carlos
Sign In or Register to comment.