小编kha*_*ril的帖子

Mustache:从子节中的父节读取变量

在子节中,Mustache可以从父节读取变量吗?

例如下面我的例子,我希望{{order_store.id}}从它的父$ order_store [(当前子循环的数组索引)] ['id']中读取变量

template.mustache

{{#order_store}}<table>
    <caption>
        Store Name: {{name}}
        Product Ordered: {{products}}
        Product Weights: {{products_weight}}
    </caption>
    <tbody>
        {{#shipping_method}}<tr>
            <td>
                <input type="radio" name="shipping[{{order_store.id}}]" id="shipping-{{id}}" value="{{id}}" /> 
                <label for="shipping-{{id}}">{{name}}</label>
            </td>
            <td>{{description}}</td>
            <td>{{price}}</td>
        </tr>{{/shipping_method}}
    </tbody>
</table>{{/order_store}}
Run Code Online (Sandbox Code Playgroud)

样本数据(PHP);

                $order_store => array(
                array(
                    'id' => 1,
                    'name' => 'Kyriena Cookies',
                    'shipping_method' => array(
                        array(
                            'id' => 1,
                            'name' => 'Poslaju',
                            'description' => 'Poslaju courier'
                        ),
                        array(
                            'id' => 2,
                            'name' => 'SkyNET',
                            'description' => 'Skynet courier'
                        ),
                    ),
                ));
Run Code Online (Sandbox Code Playgroud)

php mustache

14
推荐指数
2
解决办法
1万
查看次数

标签 统计

mustache ×1

php ×1