How can I pass variables between DRY templates and ncludes in Jekyll -


I have a simple blog site where the home page index is a list of posts, not sorted as individual pages and Has been rendered.

I have index page setup and work:

  --- layout: default ---  Div & gt; {% Included post / post.html%} {% endfor%} & lt; to post in {% Post.posts%} / Div & gt;   

Where there is a post layout using Post / PostWhite using the post variable:

  & Lt; Articles & gt; & Lt; Header & gt; {% Include / title.html%} {% include / post metadata. Html%} & lt; / Header & gt; Includes & lt; Div class = "entry-content" itemprop = "text" & gt; {{Post.content}} & lt; / Div & gt; & Lt; / Article & gt;  

Now, on a specific post page, I want to include it in the layout so that I can keep my code DRY, so I have post.html layout (Different from posts / post.html ):

  --- layout: default comments: true --- {% include post / post) Html%}  

But the problem is that the included file is expected to be such a post.content variable of posted how you can access it Are the material

I have tried:

  {% assign post = page%}  

and it seems right to pass a variable To do this, but the page is not correct because it presents a markdown string instead of html on the page.

So, how do I self - or whatever is needed - so that the file for the index page or post page does not need to be changed, thus sharing the same code Is required?

While @ David Jquel's answer is poor Kashmir, I found it impure and a little verbatim, Although it took me to the right path

{{body}} for {{PostContent}} { / P>

  & lt; Articles & gt; & Lt; Header & gt; {% Include / title.html%} {% include / post metadata. Html%} & lt; / Header & gt; Includes & lt; Div class = "entry-content" itemprop = "text" & gt; {{Body}} & lt; / Div & gt; & Lt; / Article & gt;  

_layouts / index.html now uses

  {% assign body = post content%} {% include post / Post.html%}  

_layouts / post.html Uses:

  {% assign post = page% } {% Assign body = content%} {% include post / post.html%}  

Simple.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -