문제

The tags for a post can be accessed within the post like this (using embedded Coffeescript):

<div class="tags">
Tags:
  <ul>
    <% for tag in @document.tags: %>
      <li><a class="tag_item" href="<%= @getTagUrl(tag) %>"><%= tag %></a></li>
    <% end %>
  </ul>
</div>

This generates an unordered list of the tags for this specific topic, like this:

Tags:

  • tag1
  • tag2
  • tag3

How can I generate the list of tags as comma separated values on a single line, like this:

Tags: tag1, tag2, tag3

도움이 되었습니까?

해결책

I do it like this on my blog:

<div class="post-tags">
    Posted In: <%- ("<a href='#{@getTagUrl(tag)}'>#{tag}</a>" for tag in @tags).join(', ') %>
</div>

Note, @getTagUrl comes from the docpad-plugin-tagging plugin. If you don't want hyperlinks to a page for each tag, you could simplify this to the following:

<div class="post-tags">
    Posted In: <%- (tag for tag in @tags).join(', ') %>
</div>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top