How can I see what data is available in Twig?

I’d like to put some custom info on my product pages but not sure which twig tags to use.

Is there a way to see all of the data twig can show about my product?

Sure, as you may know, in your product page design for example, you can add custom content to the page including twig variables such as:

The price of this product is {{ product.price }}.

Anything inside double curly braces will be replaced automatically when your site loads - as long as Twig understands the variable you’ve asked for. You can see a full list of the available data in Shopblocks > Settings > Twig.

To address your question… you can see inside of Twig easily by using Twig tags such as:

{{ product | json_encode() }}

This will show the entire product with all available information as a JSON object, such as:

{"id": 123, "sku": "examplesku123", "name": "Example Product 123"...

To make it more readable, try putting this in <pre> HTML tags and using pretty output formatting:

<pre>{{ product | json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>

This will output the data like:

{
  "id": 123,
  "sku": "examplesku123",
  "name": "Example Product 123"
  ...

Hope this helps!

This may be easier to read and find the product data you’re looking for.

This same trick can be used on any page to see the customer’s basket:

<pre>{{ basket | json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>