Skip to content

Variables Reference

This document provides a complete reference of all available variables in the SEO Rich Snippets module.

Variable Syntax

Variables use the {{variable.path}} syntax in JSON templates:

{
    "name": "{{product.name}}",
    "price": "{{product.finalPrice}}",
    "url": "{{config.web.secure.base_url}}"
}

How Variables Work

  1. Variable Extraction - The system scans templates for {{...}} patterns
  2. Prefix Matching - Each variable is routed to the appropriate resolver based on prefix
  3. Resolution - The resolver fetches the actual value from Magento
  4. Replacement - Variables are replaced with resolved values

Product Variables

Access product data using the product.* prefix.

Basic Product Information

Variable Description Example Output
{{product.name}} Product name "Joust Duffle Bag"
{{product.sku}} Product SKU "24-MB01"
{{product.description}} Full description "The Joust Duffle Bag..."
{{product.shortDescription}} Short description "Perfect for the gym"
{{product.productUrl}} Product URL "https://example.com/joust-duffle-bag.html"
{{product.url}} Alias for productUrl Same as above

Product Pricing

Variable Description Example Output
{{product.price}} Regular price "34.00"
{{product.finalPrice}} Final price (after discounts) "29.99"
{{product.specialPrice}} Special price if set "29.99" or null
{{product.currency}} Currency code "USD"

Product Images

Variable Description Example Output
{{product.image}} Main product image URL "https://example.com/media/catalog/product/m/b/mb01-blue-0.jpg"

Product Gallery

For multiple images, use the productGallery collection with a loop. See Collections.

Product Attributes

Variable Description Example Output
{{product.manufacturer}} Manufacturer/Brand "Nike"
{{product.color}} Color attribute "Blue"
{{product.size}} Size attribute "Large"
{{product.{attribute_code}}} Any custom attribute Varies

Attribute Resolution

The system automatically resolves attribute option labels for select/multiselect attributes. For example, manufacturer attribute with value "123" becomes "Nike" if that's the option label.

Product Reviews & Ratings

Variable Description Example Output
{{product.reviewCount}} Number of reviews "5"
{{product.ratingSummary}} Rating on 0-100 scale "80"
{{product.ratingValue}} Rating on 1-5 scale "4.2"

Rating Scales

  • ratingSummary - Magento's native 0-100 scale
  • ratingValue - Converted to 1-5 scale for Google (formula: (ratingSummary / 100) * 4 + 1)

Product Type Information

Variable Description Example Output
{{product.typeId}} Product type "simple", "configurable", "bundle"

Configuration Variables

Access Magento configuration using the config.* prefix.

Store Information

Path: Stores → Configuration → General → Store Information

Variable Description Config Path
{{config.general.store_information.name}} Store name general/store_information/name
{{config.general.store_information.phone}} Store phone general/store_information/phone
{{config.general.store_information.street_line1}} Street address general/store_information/street_line1
{{config.general.store_information.city}} City general/store_information/city
{{config.general.store_information.postcode}} Postal code general/store_information/postcode
{{config.general.store_information.country_id}} Country code general/store_information/country_id

Store Email Addresses

Path: Stores → Configuration → General → Store Email Addresses

Variable Description Config Path
{{config.trans_email.ident_general.name}} General contact name trans_email/ident_general/name
{{config.trans_email.ident_general.email}} General contact email trans_email/ident_general/email

Web Configuration

Variable Description Config Path
{{config.web.unsecure.base_url}} HTTP base URL web/unsecure/base_url
{{config.web.secure.base_url}} HTTPS base URL web/secure/base_url

Custom Configuration

You can access any Magento configuration value using the path format:

{{config.section.group.field}}

Example:

{
    "locale": "{{config.general.locale.code}}",
    "timezone": "{{config.general.locale.timezone}}"
}

Store Variables

Access current store information using the store.* prefix.

Variable Description Example Output
{{store.name}} Store name "Main Website"
{{store.code}} Store code "default"
{{store.baseUrl}} Base URL "https://example.com/"
{{store.currencyCode}} Currency code "USD"

Enum Variables

Pre-defined enumeration values for common Schema.org properties.

Availability

Variable Output
{{enum.availability.InStock}} "https://schema.org/InStock"
{{enum.availability.OutOfStock}} "https://schema.org/OutOfStock"
{{enum.availability.PreOrder}} "https://schema.org/PreOrder"
{{enum.availability.Discontinued}} "https://schema.org/Discontinued"

Item Condition

Variable Output
{{enum.itemCondition.NewCondition}} "https://schema.org/NewCondition"
{{enum.itemCondition.UsedCondition}} "https://schema.org/UsedCondition"
{{enum.itemCondition.RefurbishedCondition}} "https://schema.org/RefurbishedCondition"

Price Valid Until

Variable Description Example Output
{{enum.priceValidUntil}} End of next year "2025-12-31"

Usage Example

{
    "@type": "Offer",
    "availability": "{{enum.availability.InStock}}",
    "itemCondition": "{{enum.itemCondition.NewCondition}}",
    "priceValidUntil": "{{enum.priceValidUntil}}"
}

Snippet Variables

Reference other snippets using the snippet.* prefix.

Variable Description
{{snippet.{identifier}}} Embeds another snippet by identifier

Example: Nested Snippets

Offer Snippet (identifier: offer):

{
    "@type": "Offer",
    "price": "{{product.finalPrice}}",
    "priceCurrency": "{{store.currencyCode}}"
}

Product Snippet using the offer:

{
    "@type": "Product",
    "name": "{{product.name}}",
    "offers": "{{snippet.offer}}"
}

Rendered Output:

{
    "@type": "Product",
    "name": "Joust Duffle Bag",
    "offers": {
        "@type": "Offer",
        "price": "34.00",
        "priceCurrency": "USD"
    }
}

Nesting Limits

  • Maximum nesting depth: 5 levels
  • Circular dependency protection prevents infinite loops
  • Example: Product → Offer → Organization → Address → Contact (5 levels)

Collections

Collections are used with DJson loops to iterate through arrays of data.

Product Reviews Collection

Collection: productReviews

Usage:

{
    "@djson for productReviews as review": {
        "@type": "Review",
        "author": "{{review.nickname}}",
        "reviewBody": "{{review.detail}}",
        "datePublished": "{{review.createdAt}}"
    }
}

Available Fields: - {{review.nickname}} - Reviewer name - {{review.detail}} - Review text - {{review.title}} - Review title - {{review.createdAt}} - Review date (ISO 8601) - {{review.reviewId}} - Review ID

Collection: breadcrumbs

Usage:

{
    "@djson for breadcrumbs as breadcrumb": {
        "@type": "ListItem",
        "position": "{{breadcrumb.position}}",
        "name": "{{breadcrumb.label}}",
        "item": "{{breadcrumb.link}}"
    }
}

Available Fields: - {{breadcrumb.position}} - Position in breadcrumb trail - {{breadcrumb.label}} - Breadcrumb text - {{breadcrumb.link}} - Breadcrumb URL

Product Listing Collection

Collection: products

Context: Category pages, search results

Usage:

{
    "@djson for products as product": {
        "@type": "ListItem",
        "position": "{{product.position}}",
        "url": "{{product.productUrl}}",
        "name": "{{product.name}}"
    }
}

Available Fields: Same as Product Variables

Collection: productGallery

Usage:

{
    "@djson for productGallery as image": {
        "@type": "ImageObject",
        "url": "{{image.url}}",
        "width": "{{image.width}}",
        "height": "{{image.height}}"
    }
}

Available Fields: - {{image.url}} - Image URL - {{image.width}} - Image width in pixels - {{image.height}} - Image height in pixels

Variable Resolution Examples

Example 1: Product with Reviews

{
    "@context": "https://schema.org/",
    "@type": "Product",
    "name": "{{product.name}}",
    "sku": "{{product.sku}}",
    "image": "{{product.image}}",
    "offers": {
        "@type": "Offer",
        "price": "{{product.finalPrice}}",
        "priceCurrency": "{{store.currencyCode}}"
    },
    "@djson if product.reviewCount": {
        "aggregateRating": {
            "@type": "AggregateRating",
            "ratingValue": "{{product.ratingValue}}",
            "reviewCount": "{{product.reviewCount}}"
        }
    }
}

Output:

{
    "@context": "https://schema.org/",
    "@type": "Product",
    "name": "Joust Duffle Bag",
    "sku": "24-MB01",
    "image": "https://example.com/media/catalog/product/m/b/mb01-blue-0.jpg",
    "offers": {
        "@type": "Offer",
        "price": "34.00",
        "priceCurrency": "USD"
    },
    "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": "4.2",
        "reviewCount": "5"
    }
}

Example 2: Organization with Configuration

{
    "@context": "https://schema.org/",
    "@type": "Organization",
    "name": "{{config.general.store_information.name}}",
    "url": "{{config.web.secure.base_url}}",
    "telephone": "{{config.general.store_information.phone}}",
    "email": "{{config.trans_email.ident_general.email}}",
    "address": {
        "@type": "PostalAddress",
        "streetAddress": "{{config.general.store_information.street_line1}}",
        "addressLocality": "{{config.general.store_information.city}}",
        "postalCode": "{{config.general.store_information.postcode}}",
        "addressCountry": "{{config.general.store_information.country_id}}"
    }
}

Example 3: Custom Attribute Access

For a custom manufacturer attribute:

{
    "@type": "Product",
    "name": "{{product.name}}",
    "brand": {
        "@type": "Brand",
        "name": "{{product.manufacturer}}"
    }
}

The system automatically: 1. Checks if manufacturer is an attribute 2. Gets the attribute value 3. Resolves option label if it's a select attribute 4. Returns the label (e.g., "Nike" instead of option ID "123")

Advanced Variable Techniques

Conditional Variables

Use @djson if to check if a variable exists:

{
    "@djson if product.manufacturer": {
        "brand": {
            "@type": "Brand",
            "name": "{{product.manufacturer}}"
        }
    }
}

Nested Variable Resolution

Variables can reference nested data:

{
    "seller": "{{snippet.organization}}",
    "manufacturer": "{{product.manufacturer}}"
}

Both snippet.organization and product.manufacturer are resolved independently.

Loop Variables

Inside loops, use the loop variable name as prefix:

{
    "@djson for productReviews as review": {
        "author": "{{review.nickname}}",
        "text": "{{review.detail}}"
    }
}

Troubleshooting Variables

Variable Not Resolving

Symptom: {{product.name}} appears in output instead of actual value

Solutions: 1. Check variable path is correct 2. Verify data exists (e.g., product is loaded) 3. Check resolver is registered in di.xml 4. Enable debug logging

Null Values

Symptom: Variable resolves to null or empty string

Solutions: 1. Check if the data actually exists in Magento 2. Use @djson if to conditionally show the field 3. Provide default values in your template

Incorrect Attribute Values

Symptom: Attribute shows ID instead of label (e.g., "123" instead of "Nike")

Solutions: 1. Ensure attribute is properly configured in Magento 2. Check attribute frontend input type 3. Use ProductValueResolver which handles option labels automatically

Next Steps