HEXO的EJS模板引擎语法 如何判断子分类时第一个输出的时候

KOK (UID: 3119) 1月前

358 0

 

如图,目的是,在TAB面板里我输出第一个分类的时候 CLASS添加active 。  但我写如下代码 没有效果

 

<% if (e.submenu) { %>
  <% for (let i = 0; i < e.submenu.length; i++) { %>
    <% if (i === 0) { %>
      当作为第一个输出的时候
    <% } else { %>
      
其他

    <% } %>
  <% } %>
<% } %>

 

页面代码如下:

                <% if(is_home() || isChildPage){ %>
                    <% const menuSetting = isChildPage ? page : theme; %>
                      <% menuSetting.menu.forEach(function(e) { %>
                      <% if (e.submenu) { %>
                        <div class="d-flex flex-fill" id="<%= e.name.replace(/[\s]+/g, '-') %>">
                            <h4 class="text-gray text-lg mb-4">
                                <i class="fa fa-edit icon-fw mr-2"></i>
                                <%= e.name %>
                            </h4>
                            <div class="flex-fill"></div>
                          </div>
                          <div class="d-flex flex-fill flex-tab align-items-center">
                            <div class='overflow-x-auto slider_menu mini_tab' slidertab="sliderTab" >
                                <ul class="nav nav-pills menu" role="tablist">
                                  <% e.submenu.forEach(function(z) { %>
                                    <li class="pagenumber nav-item" data-id="10">
                                        <a id="<%= z.name.replace(/[\s]+/g, '-') %>" class="nav-link active" data-toggle="pill" href="#tab-<%= z.name.replace(/[\s]+/g, '-') %>" data-link=""><%= z.name %></a>
                                    </li>
                                    <% }) %>
                                </ul>
                            </div>
                            <div class="flex-fill"></div>
                          </div>
                          <div class="tab-content mt-4">
                      <% e.submenu.forEach(function(e) { %>
                      <% const childPath = page.path.replace('index.html', '') + e.config; %>
                      <% const key = isChildPage?childPath:e.config; %>
                      <% var menus = site.data && site.data[key] ? site.data[key] : menuSetting[e.config]; %>
                      <%- partial('common/groupe.ejs', {e: e, menus: menus || []}); %>
                      <% }) %>
                    </div>
                    <br />
                      <% } else { %>
                      <% const childPath = page.path.replace('index.html', '') + e.config; %>
                      <% const key = isChildPage?childPath:e.config; %>
                      <% var menus = site.data && site.data[key] ? site.data[key] : menuSetting[e.config]; %>
                      <%# console.log(page.path,childPath,key); %>
                      <%- partial('common/group.ejs', {e: e, menus: menus || []}); %>
                      <% } %>
                      <% }) %>
                      <% } %>

 

groupe.ejs 代码如下:

<% if (e.submenu) { %>
        <% for (let i = 0; i < e.submenu.length; i++) { %>
          <% if (i === 0) { %>
    <div id="tab-<%= e.name.replace(/[\s]+/g, '-') %>" class="tab-pane active">  
        <div class="row sortable" id="10">
          <% menus.forEach(function(menu) { %>
        <div class="url-card col-6 col-sm-6 col-md-4 col-xl-5a col-xxl-6a" id="157">
        <div class="url-body default">
            <a href="<%= url_for(menu.url) %>"  target="_blank" data-url="<%= url_for(menu.url) %>" class="card no-c mb-4" data-placement="bottom" data-toggle="tooltip" data-original-title="<%= menu.description %>">
                <div class="card-body">
                    <div class="url-content d-flex align-items-center">
                        <div class="url-img mr-2 d-flex align-items-center justify-content-center">
                            <img class="lazy" data-src="<%= url_for(menu.img) %>" >
                        </div>
                        <div class="url-info flex-fill">
                            <div class="text-sm overflowClip_1">
                                <strong><%= menu.name %></strong>
                            </div>
                            <p class="overflowClip_1 m-0 text-muted text-xs"><%= menu.description %></p>
                        </div>
                    </div>
                </div>
            </a>
            <a href="" tppabs="<%= url_for(menu.url) %>" class="togo text-center " data-toggle="tooltip" data-placement="right" title="直达" rel="nofollow">
                <i class="iconfont icon-goto"></i>
            </a>
        </div>
    </div>
        <% }) %>
        </div>
    </div>

    <% } else { %>
        <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
    <% } %>
  <% } %>
<% } %>

 

博客 kok.plus
已有评论 (0)
    暂无回复,快来抢沙发吧

    暂无回复,快来抢沙发吧

    • 大佬论坛
      1
      登录后才可回帖  登录 注册

本站同款香港KC服务器 酷盾安全联盟 智能优化防护 ROOVPS 便宜服务器 盾云SCDN 月付只需1元起