I've been looking into the drupal 8 commerce module, I want to take the variable $count that is generated within
../commerce/modules/cart/src/plugin/block/CartBlock.php
and place it into a custom block in my own theme. I see that the build() function returns the count variable through #count which can then be accessed via twig. Just for reference Drupal commerce currently uses the template:
../commerce/modules/cart/templates/commerce-cart-block.html.twig
to output the variables and markup:
<div{{ attributes}}>
<div class="cart-block--summary">
<a class="cart-block--link__expand" href="{{ url }}">
<span class="cart-block--summary__icon">{{ icon }}</span>
<span class="cart-block--summary__count">{{ count_text }}</span>
</a>
</div>
{% if content %}
<div class="cart-block--contents">
<div class="cart-block--contents__inner">
<div class="cart-block--contents__items">
{{ content }}
</div>
<div class="cart-block--contents__links">
{{ links }}
</div>
</div>
</div>
{% endif %}
</div>
My question is, how I can I make that variable global, are there any implications to just making it global, like what if the user updates the basket?
How do I go about achieving this? Does anyone have a possible solution?