Mustache PHP - 对象数组的表示法

时间:2014-09-25 16:34:59

标签: mustache wp-query mustache.php

我使用Mustache PHP模板引擎呈现包含wordpress WP_User_Query详细信息的表格。我的SQL函数是这个

function getLinkedRunners(){
    $usersByCompanyQuery = new WP_User_Query(
            array(
                    'fields' => 'all',
                    'orderby' => 'bhaa_runner_dateofrenewal',
                    'meta_query' => array(
                            array(
                                    'key' => 'bhaa_runner_company',
                                    'value' => $this->houseid,
                                    'compare' => '=')
                    )
            )
    );
    $users = $usersByCompanyQuery->get_results();
    var_dump($users);
    return $users;
}

返回此数据结构

object(Runner)[1021]
  public 'user' => 
    object(WP_User)[3906]
      public 'data' => 
        object(stdClass)[3905]
          public 'ID' => string '6624' (length=4)
          public 'display_name' => string 'zz-zz' (length=11)
      public 'ID' => int 6624
  public 'meta' => 
    array (size=4)
      'first_name' => string 'zzzz' (length=6)
      'last_name' => string 'ccc' (length=4)
      'nickname' => string 'Adzzzzrian cccc' (length=11)
      'description' => string '' (length=0)

我可以使用Mustache模板呈现此内容

<table class="table-1">
<tr>
<th>Name</th>
<th>nickname</th>
</tr>
{{#users}}

<tr>
<td><b><a href="/runner/?id={{user.data.ID}}">{{user.data.display_name}}</a></b></td>
<td>{{meta['nickname']}}</td>
</tr>

{{/users}}
</table>

&#39; user.data.display_name&#39;字段呈现正确,但我似乎无法参考“元”中的详细信息。从胡子模板。任何人都可以建议哪种语法适用于这种情况?

0 个答案:

没有答案