Skip to main content

5 Key BigCommerce Handlebars Helpers to Improve Themes

In this article, we’ll unveil 5 essential BigCommerce Handlebars helpers that will supercharge your theme development process and elevate your BigCommerce store to new heights.

From conditional logic and data iteration to currency formatting and navigation enhancement, these helpers offer a wealth of possibilities for tailoring the user experience to perfection.

Unlock the Power of the 5 BigCommerce Handlebars Helpers

Creating dynamic and captivating BigCommerce storefronts demands a robust set of tools. The Stencil framework from BigCommerce uses Handlebars, giving developers great flexibility. However, despite the control Handlebars provide, extensive coding for common tasks can slow you down.

This is where Handlebars BigCommerce helpers come to the rescue. These pre-built functions act as your development time-savers, streamlining common tasks and enhancing code readability. By leveraging these helpers effectively, you can significantly elevate your BigCommerce theme development.

Here’s a closer look at five essential BigCommerce Handlebars helpers that will supercharge your theme development:

json – Effortless Data Inspection and Debugging:

  • Functionality: Transforms JavaScript objects into readable JSON strings, providing a clear and structured view of your data.
  • Benefits: It simplifies debugging by allowing you to inspect complex data structures during the development and troubleshooting phases.
  • Example:

<!– context = {

    object: { a: 1, b: “hello” }

} –>

{{json object}}

<!– => ‘{“a”:1,”b”:”hello”}’ –>

concat – Streamlined String Concatenation:

  • Functionality: Combines 2 strings from your page’s context into a single string.
  • Benefits: Simplifies URL generation, dynamic component creation, and other tasks that involve joining strings.
  • Example:

{{concat ‘hello’ ‘world’}}

<!– => helloworld –>

moment – Mastering Time-Based Functionalities:

  • Functionality: References the precise moment the helper is called, enabling you to manipulate time-based functionalities.
  • Benefits:
    • Enables cache-busting for image assets on your CDN by incorporating the current timestamp as a parameter, ensuring that the latest version is retrieved.
    • Facilitates dynamic date and time formatting based on the user’s locale.
  • Example:

{{moment “5 hours ago” “MM/DD/YYYY HH:mm”}}

<!– example calculation –>

If you encounter an issue with the last day of the month, use one of the following fixes:

{{moment date format datejs=false}}

<!– To disable date.js →

{{moment “January 1, 2022″ format=”YYYY-MM-DD”}}

<!– To call moment.js functions –>

filter – Conditional Component Display:

  • Functionality: Filters data within your Stencil context and displays custom components based on specific criteria.
  • Benefits: Enhances dynamic content display by allowing you to conditionally show or hide components based on product details or other factors.
  • Example:

<!– array: [‘a’, ‘b’, ‘c’] –>

{{#filter array “foo”}}AAA{{else}}BBB{{/filter}}

<!– results in: ‘BBB’ –>

jsContext – Bridging the Gap Between Page Context and JavaScript Apps:

  • Functionality: Acts as a bridge between a page’s context and JavaScript applications, allowing apps to access resources available on that page.
  • Benefits: Enables communication and data exchange between your Stencil theme and JavaScript applications, fostering a more integrated development experience.
  • Example:

{{#partial “head”}}

    {{#if pagination.category.previous}}

        <link rel=”prev” href=”{{pagination.category.previous}}”>

    {{/if}}

    {{#if pagination.category.next}}

        <link rel=”next” href=”{{pagination.category.next}}”>

    {{/if}}

{{/partial}}

Read more: Next.js BigCommerce: The Ultimate E-commerce Solution

Bottom line

By mastering these essential BigCommerce Handlebars helpers, you’ll equip yourself with powerful tools to streamline your theme development process.