Hi - I am trying to add the number of individual basket items to my page, but don’t want to include the quantity of each item. Is this possible?
Hi Mike,
Sure - you can use Twig tags for this purpose.
To access the customer’s basket, the {{ basket }}
tag can be used - this contains lots of information - to see it all on the page you can use {{ basket | json_encode(constant('JSON_PRETTY_PRINT')) }}
for example.
To answer your specific question - to show just the number of line items in a customer’s basket you could do the following:
-
Log in to Shopblocks and go to BlockLab. Then edit any of your site’s layouts, such as the Header.
-
Add a “HTML” block to the page.
-
In the HTML block add:
<p>You have {{ basket.items | length | default(0) }} items in your basket.</p>
-
Save and publish
-
Go to your site and you should see “0 items” until you add to basket, and then see the number of line items, ignoring the quantity of each line item.
Amazing - that worked! Thanks