2

I would like to define a list of featured category IDs within my homepage template. Is it possible to define a custom variable in the front matter? I can't seem to get it working:

Here is the default front-matter in templates/pages/home.html with my custom variable, featured_categories at the end:

---
products:
    new:
        limit: {{theme_settings.homepage_new_products_count}}
    featured:
        limit: {{theme_settings.homepage_featured_products_count}}
    top_sellers:
        limit: {{theme_settings.homepage_top_products_count}}
carousel: {{theme_settings.homepage_show_carousel}}
blog:
    recent_posts:
      limit: {{theme_settings.homepage_blog_posts_count}}
featured_categories: 'testing'
---

Then, in the template, this line is not producing any output:

{{featured_categories}}

Why doesn't this output the value testing? Ultimately, I would like featured_categories to be an array of category ID's. Is this possible to do using front matter?

flyingL123
  • 7,686
  • 11
  • 66
  • 135

1 Answers1

1

It is not possible to declare a custom front matter variable as those have to be determined in the framework by BigCommerce. You can import handlebars yourself and define a variable, but it would execute client side and not server side for security reasons.

JJS
  • 6,431
  • 1
  • 54
  • 70
Alyss
  • 1,866
  • 1
  • 13
  • 27
  • 3
    I added `"featured_categories": "testing"` to the `settings` object in `config.json`, and was then able to access it in the template via `{{ theme_settings.featured_categories`. I guess this is a good workaround. – flyingL123 Mar 02 '16 at 20:11
  • 3
    Looks like it works with arrays too: `"featured_categories": [1,2,3]` allows me to iterate over `theme_settings.featured_categories` in the template. – flyingL123 Mar 02 '16 at 20:13