Home > Articles > 5 Key BigCommerce Handlebars Helpers to Improve Themes

5 Key BigCommerce Handlebars Helpers to Improve Themes

April 12, 2024
Written and researched by experts at AvadaLearn more about our methodology

By Sam Nguyen

CEO Avada Commerce

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” }

} –>

<!– => ‘{“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:

<!– => 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:

<!– example calculation –>

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

<!– To disable date.js →

<!– 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’] –>

AAABBB

<!– 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:

    

        <link rel=”prev” href=””>

    

    

        <link rel=”next” href=””>

    

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. 


Sam Nguyen is the CEO and founder of Avada Commerce, an e-commerce solution provider headquartered in Singapore. He is an expert on the Shopify e-commerce platform for online stores and retail point-of-sale systems. Sam loves talking about e-commerce and he aims to help over a million online businesses grow and thrive.