【问题标题】:Bigcommerce Stencil declare custom front-matter variableBigcommerce Stencil 声明自定义前端变量
【发布时间】:2016-06-15 21:07:33
【问题描述】:

我想在我的主页模板中定义一个特色类别 ID 列表。是否可以在前端定义自定义变量?我似乎无法让它工作:

这是templates/pages/home.html 中的默认前端,最后是我的自定义变量featured_categories

---
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'
---

然后,在模板中,这一行不会产生任何输出:

{{featured_categories}}

为什么不输出值testing?最终,我希望featured_categories 成为一个类别 ID 的数组。这可以使用前置物质吗?

【问题讨论】:

    标签: handlebars.js bigcommerce yaml-front-matter


    【解决方案1】:

    无法声明自定义前端变量,因为这些变量必须由 BigCommerce 在框架中确定。您可以自己导入把手并定义一个变量,但出于安全原因,它将执行客户端而不是服务器端。

    【讨论】:

    • 我在config.jsonsettings 对象中添加了"featured_categories": "testing",然后可以通过{{ theme_settings.featured_categories 在模板中访问它。我想这是一个很好的解决方法。
    • 看起来它也适用于数组:"featured_categories": [1,2,3] 允许我在模板中迭代 theme_settings.featured_categories
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-30
    相关资源
    最近更新 更多