Which way of including content multiple times into one layout in Docpad is most appropriate? -


i've started digging docpad current project , far i've discovered 3 ways include content.

  • we use content template data variable include child layout/document layout.
  • we have include(relativepath) method include content of file @ given path.
  • finally have partials plugin provides way insert documents other documents, , passed docpad rendering engine.

we can use content variable once per document. have multiple places within static template need include content. why ever need use content variable if can use, say, include, or partials (when installed) not have limit of single usage per document? guess there own pros, cons , use cases each way of including content. i'm wondering way appropriate , in case, assuming want include content multiple times in 1 layout?

ok - think know trying do. there may various places on page might want have content. standard way use partials in each of places want content. also, remember can call partials within partial. example of page have blog:

 <% doc in @getcollection('posts').tojson(): %>        <%- @partial('content/post.html.eco',{document:doc,showcomments:false}) %> <div class="hr clearfix">&nbsp;</div>  <% end %>  

in partial have:

 <article class="panel">      <header>         <h3 class="title"><a href="<%= @document.url.replace(/\\/g, '/') %>"><%=@document.title%></a><time datetime="<%=@document.date.toisostring()%>" class="postdate"><%=@document.date.todatestring()%></time></h3>     </header>      <!-- post data -->     <p class="sub"><strong class="tag_bg"></strong>     <%for tag in @document.tags: %>         <a class="catlink" href="/"><%=tag%></a>      <%end%>     <a class="commentlink" href="#">0</a>     </p>      <% if (@document.image):%>     <figure>          <a class="islink_m" href="#" data-rel="prettyphoto[mixed]" title="<%=@document.title%>"></a>         <span class="image-holder-medium">             <img class="thumb" style="display:block;margin-left:auto;margin-right:auto;" alt="" src="<%=@document.image%>"></span>      </figure>     <%end%>      <p><%-@document.content%></p>      <footer>         <%if(@showcomments):%>     <%- @partial('content/social.html') %>     <%- @partial('content/disqus.html.eco', {site:@site,document: @document}) %>         <%end%>     </footer>  </article> 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -