V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
foonnnnn
V2EX  ›  Django

請問這個效果,應該是用Cycle嗎?

  •  
  •   foonnnnn · May 14, 2013 · 4056 views
    This topic created in 4741 days ago, the information mentioned may be changed or developed.
    我想它在首位的li>class設置active,而尾的li>class設置last.

    <ul>
    <li class='active'><a href='#'><span>Home</span></a></li>
    <li><a href='#'><span>Products</span></a></li>
    <li><a href='#'><span>Company</span></a></li>
    <li class='last'><a href='#'><span>Contact</span></a></li>
    </ul>
    -------------------------------------

    <div id='cssmenu'>
    {% for child in children %}
    {% cycle 'active' 'last' as cssmenu silent %}
    <li class="{{cssmenu}}">
    <a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title }}</a>
    {% if child.children %}
    <ul>
    {% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
    </ul>
    {% endif %}
    </li>
    {% endfor %}
    </div>
    2 replies    1970-01-01 08:00:00 +08:00
    Archangel_SDY
        1
    Archangel_SDY  
       May 14, 2013
    https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for

    在循环里面用forloop.first/forloop.last判断吧.
    foonnnnn
        2
    foonnnnn  
    OP
       May 14, 2013
    成功了!!!!!!!!! 謝謝你!!!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1518 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 16:43 · PVG 00:43 · LAX 09:43 · JFK 12:43
    ♥ Do have faith in what you're doing.