面包屑中的CakePHP内容计数

k4emjkb1  于 2022-11-12  发布在  PHP
关注(0)|答案(1)|浏览(157)

我正在使用cakephp面包屑助手,我有面包屑模板

$this->Breadcrumbs->setTemplates([
                'wrapper' => '<nav aria-label="breadcrumb">
                                <ol {{attrs}}> {{content}}
                                </ol>
                              </nav>',
                'item' => '<li  {{attrs}}>
                                <a itemprop="item" href="{{url}}"{{innerAttrs}}>
                                <span>{{title}}</span></a> 
                                <meta content={{count}}> 
                           </li>{{separator}}',
]);

在 meta内容中,我需要像1、2、3这样计数...
我的当前输出

<nav>
   <ol>
      <li>
          <a href=""></a>
          <meta itemprop = "position" content>
      </li>

   </ol>
</nav>

期望输出:

<nav>
       <ol>
          <li>
              <a href=""></a>
              <meta itemprop = "position" content=1>  <-- desire output 
          </li>

       </ol>
    </nav>

我可以通过JavaScript来实现。是否可以使用cakephp breadcrumbs helper在 meta内容(<meta content={{count}}〉)中动态地放置列表计数?

ht4b089n

ht4b089n1#

CakePHP手册:自定义输出

$this->Breadcrumbs->add(
    'Products',
    ['controller' => 'products', 'action' => 'index'],
    [
        'class' => 'products-crumb',
        'data-foo' => 'bar',
        'count' => 1 //<----------------------------
        'innerAttrs' => [
            'class' => 'inner-products-crumb',
            'id' => 'the-products-crumb'
        ]
    ]
);

// Based on the default template, this will render the following HTML:
<li class="products-crumb" data-foo="bar">
    <a href="/products/index" class="inner-products-crumb" id="the-products-crumb">Products</a>
    <meta itemprop = "position" content=1>  <-- desire output

</li>

相关问题