【问题标题】:Front Matter Global Variable on all pages in BigCommerce themeBigCommerce 主题中所有页面上的 Front Matter 全局变量
【发布时间】:2017-04-23 00:46:06
【问题描述】:

当用户将鼠标悬停在我的导航中显示帐户信息(例如以前的订单)时,我正在尝试创建一个下拉菜单。

我正在使用 Stencil/Cornerstone。我尝试使用

page.html 上声明一个 Front Matter 对象
---
customer: 
    orders: 
        limit 5
--- 

但这似乎不起作用,菜单拉客户订单的唯一地方是用户是否在帐户页面上。我需要它在所有页面上都可用,因为它是网站的主导航。

菜单栏.html

(sn-p)

{{#if customer}}
    <li class="nav-page"><a href="/account.php">My Account</a>
        <div class="sub-menu">
            <div class="nav-col">
                <h4>Hello, {{customer.name}}</h4>
            </div>
            <div class="nav-col">
                <!-- orders -->
                <h5>Orders</h5>
                <ul class="account-order-list">
                    {{#if customer.orders}} {{#each customer.orders}}
                    <li><a href="{{details_url}}"><i class="fa fa-tag" aria-hidden="true"></i> Order #{{id}}</a>
                        <div class="order-details-list">
                            <a class="details" href="{{details_url}}">
                                <span><strong>Date:</strong> {{date}} </span>
                                <span><strong>Amount:</strong> {{total.formatted}} </span>
                                <span><strong>Status:</strong> {{status}}</a></span>

                        </div>
                    </li>
                    {{/each}} {{else}}
                    <span>You have no orders.</span> {{/if}}
                </ul>
            </div>
            <div class="nav-col">
                <h5></h5>
            </div>
        </div>
    </li>
    {{else}}
    <li class="nav-page"><a href="/login.php">Sign In</a></li>
    {{/if}}
</ul>

【问题讨论】:

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


    【解决方案1】:

    从 jekyll/liquid 的角度来看,如果你想要一个全局变量,你可以声明它:

    1 - 在 _config.yml

    customer: 
        orders: 
            limit: 5 # and not "limit 5"
    

    并像这样使用它:{{ site.customer.orders.limit }}

    2 - 或在通用(所有页面)布局中,如 _layouts/default.html

    它将在任何页面中提供:{{ page.customer.orders.limit }}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 2020-02-19
      • 2014-04-18
      • 2016-03-19
      相关资源
      最近更新 更多