What are the contexts available for twig logic constructs?

carlos123carlos123 Member
in Help edited September 2014
I want certain notes to appear only on the checkout page. While I could just replace the cart include twiggly thing with the actual cart include code and thus isolate the note within the checkout template I would like to use some twig logic to output that note (from within the cart include) only when the context is the 'checkout' (which I assume si the checkout page).

So I've done this inside the cart include...
            {# Per Carlos: added note to checkout under the cart sidebar #}
            {% if context == "checkout" %}
            <p class="xxxx_cart_note">TBD (in place of a shipping charge) stands for To Be Determined and will be updated with a correct charge when you update your shipping address to indicate <b>both</b> the country <b>and</b> zip or postal code.</p>
            {% endif %}

I think that's right (if anyone sees different please let me know).

However I am wondering what the contexts are?

What contexts are available (in case I want to do some other conditional rendering of this or that)?

I know there are the 'checkout', 'cart', 'receipt' but is there an 'email' and perhaps some others also?

Is there any documentation anywhere that outlines what these contexts are and lists them?

For example...I think the 'cart' context is the full on cart display on it's own page (fancybox actually) and not the sidebar "cart" that appears on the checkout page but am not absolutely certain of that.

Carlos





Tagged:
Comments
  • fc_adamfc_adam FoxyCart Team
    @carlos123,

    Good question. Currently we just have 'cart', 'checkout' and 'receipt' - and 'cart' does cover both the Sidecart and full page versions of the cart. We have a supplementary boolean variable for 'cart_is_fullpage' which you can use to differentiate between Sidecart and the full page cart.

    For documentation of context and all the different variables contained in FC.json (which is what is used within the templates as well) can be seen at the bottom of this page: http://wiki.foxycart.com/static/redirect/templates

    Also for what it's worth - we're almost finished a quick rewrite of that templates page to break it out into different sections to make it easier to take in, and also bulk out our documentation of templates.
  • Welcome back Adam! I missed your excellent input.

    Hmm...does the Sidecart ONLY show up on the checkout page or elsewhere as well?

    I want to isolate the notes I am displaying on the checkout page under the cart to showing up...well...ONLY under the side cart on the checkout page and no where else. It's working but I have not yet seen a receipt or other items so it's hard to tell where the notes will show up next LOL.

    Thanks for the link to the template stuff Adam. I've seen that page several times and have tried to read through it several times as well and...well...I usually can't get very far before my eyes fog over and my mind goes wandering.

    It's a VERY confusing page filled with assumptions about what those reading it should know.

    Not a very helpful page at all.

    Outstanding and congratulations on being almost done with an improvement in documentation. I look forward to seeing it.

    Carlos
  • fc_adamfc_adam FoxyCart Team
    @carlos123,

    Yeah - the templates page is huge - which is why our little update will be breaking it out into different pages to hopefully make that more consumable.

    One quick clarification - "Sidecart" references the cart that slides in on your own website.

    So if you're wanting to only show a note in the cart on the checkout page - you would want to do exactly what you've pasted in your first post, and check if the context is equal to "checkout'.
  • Oh okay. Good to know.

    So the boolean cart_is_fullpage is for when the cart is shown on a..I am guessing...full page rendering.

    Whereas sidecart is for when...hmm...it shows up inside a fancy box or something?

    Not clear on the difference between these two supposed contexts Adam.

    It's rather academic at this point since using the checkout context accomplishes what I want but...you never know when I might find a good understanding of this in the future beneficial.

    Carlos

  • fc_adamfc_adam FoxyCart Team
    @carlos123,

    If you view our examples page here: http://www.foxycart.com/features/examples - when you click one of the add to carts, the cart slides in from the right hand side - that's a feature that we refer to as "Sidecart".
  • I see...

    So the sidecart context refers to when the cart actually slides in from the side of a page?

    Whereas the cart_is_fullpage refers to when it doesn't and appears rather in a fancy box or as a new page or otherwise?

    Is that correct?

    Carlos
  • fc_adamfc_adam FoxyCart Team
    @carlos123,

    Yes - so full page cart would be when you view your cart directly like in 'https://yourstore.foxycart.com/cart'
  • So the contexts then are:

    - cart
    - checkout
    - receipt

    Where one can drill down even further within the cart context to differentiate between when the cart appears from the side of the page (context: sidecart) or otherwise (context: cart_is_fullpage).

    Does that cover all the available contexts?

    Carlos
  • What's confusing in this Adam is the terminology that you guys are using.

    To me it would have been clearer if you all would have referred to the context where the cart appears from the side of the screen into the page as the cart_from_side context and any other context for the cart as the cart_on_page context.

    Sidecart sounds too much like the cart that appears at the side of the checkout which is what I naturally thought it referred to.

    For what it's worth.

    Carlos
  • fc_adamfc_adam FoxyCart Team
    @carlos123,

    That's great feedback - I'll pass that onto the team.

    One thing to note here that might help - when the cart is on the checkout for example - the cart in that sense doesn't have it's own context. The context for the page is "checkout", so that's the context that the cart that is displayed there will have as well.

    If you want to target the cart as it's displayed in the checkout, then you just work off of the context "checkout". Similarly, for the receipt, you'd work off of "receipt". If you want to target the cart when it appears within the sidebar, then you would target contexts of "checkout" and "receipt" as that's where it's displayed that way.

    Does that clear things up at all?
  • Absolutely clear Adam. As always your input is excellent!

    Carlos
Sign In or Register to comment.