Skip to content
This repository has been archived by the owner on Nov 29, 2017. It is now read-only.

Creating static pages from markdown and evaluating liquid tags. #51

Closed
DanNordness opened this issue May 21, 2014 · 9 comments
Closed

Comments

@DanNordness
Copy link

So I'd like to be able to create static pages from a markdown file in the same way I'd make a blog post from a markdown file, but I can't figure out a way to get jekyll to render liquid content in any markdown file that isn't in _posts/

Is this even possible? I mean I suppose I could put my page in posts and handle the case with something hacky, but I'd really like to be able to generate my site/about page from liquid tags laden markdown.

So far I've got this. It evaluates the markdown content but totally ignores the liquid tags.

_includes/about.md


---
title: about

---
La La La
{%some liquid tag%}

and in about.html


---
layout: layout

---

{% capture about %}{% include about.md %}{% endcapture %}
{{ about  | markdownify }}

My output in the site/about page is just:

La La La

@parkr
Copy link
Member

parkr commented May 21, 2014

Make sure you include {{ content }} in your layout. That will output the converted and rendered version of any page which specifies it as its layout.

@DanNordness
Copy link
Author

Well, that's the issue, right?

I have an about.html file sitting in jekyll's root directory which itself has a layout _layouts/about_layout

I can include my about.md file in about.html but then when the layout evaluates it the liquid tags have been removed. I guess I don't understand how I should be structuring this to achieve my goal.

Right now I've got:
_includes/about.md being included in about.html (a page) whose layout is _layouts/about layout

@jaybe-jekyll
Copy link
Member

Front matter, in this case- "layout: ", in an included file, will not be parsed as you are supposing.

The main index file should possess the "layout: " specification, i.e.:

./about/index.html

---
title: About
layout: about
---

## How about this?

{% include some-about-include.include %}

./_layouts/about.html

---
layout: sub-layout-if-desired
---

<div class="about-class">
... {{ content }}
</div>

./_includes/some-about-include.include

{% for bout in site.about %}
  {{ bout.title }}
{% endfor %}

## Some Markdown will work

- But you will need to filter through `mardownify`
  - (of course)

@DanNordness
Copy link
Author

But that's not the issue I'm having. My current setup works for evaluating markdown in the include but it does not evaluate any of the liquid tags in the markdown which is what I want.

The markdownify filter just throws away all my liquid tags.

@jaybe-jekyll
Copy link
Member

Do you wish for for the liquid code to be evaluated and produce output based on the evaluation?

Or, are you wishing for the liquid code itself to be (re)produced and output/shown?

Perhaps restate your goal, from the top, succinctly.

Liquid within included files can be, and is, evaluated and produces evaluated output, as expected.

Example:

./_includes/posts.include

{% for post in site.posts %}
  {{ post.title }}
{% endfor %}

./_layouts/default.html

<html>
  <head>...</head>
  <body>
    {{ content }}
  </body>
</html>

./about/index.html

---
title: "My About Page"
layout: default
---

## This is my About Page

- Here is a list of posts:

{% include posts.include %}

### Have a nice day

@parkr
Copy link
Member

parkr commented May 21, 2014

An example repository would also be very helpful.

@DanNordness
Copy link
Author

Sorry for the lack of clarity.

I think I figured out what was going on. Thanks for the help and great examples!

@duanefields
Copy link

Can you explain what the resolution was? I have having the same question....

@wilzbach
Copy link

Hi @duanefields,

I recently encountered a similar problem when I wanted to include projects which are independent jekyll pages on a summary page.

My ideas were

As I needed to get this working for github pages (=without plugins), my workaround is a combination of both and looks horrible - I would be very happy if this gets fixed in a future release and there is an easier way to include a jekyll page in another jekyll page :)

Basically it loops over all pages, picks the one I want to include, uses their filePath to call include_relative and then strips the YAML front matter.

{% for p in include.pages %}
 {% if p.gsoc == include.gsocYear %}

 {% capture inpath %}{{page.gsocYear}}/projects/{{ p.name }}{% endcapture %}

 {% capture content %}{% include_relative {{inpath}} %}{% endcapture %}

<!-- probably the ugliest way to remove the YAML front matter -->
{% assign lines = content | newline_to_br | split: "<br />" %}

{% assign newContent = "" %}
{% for l in lines %}
    {% if forloop.index >= 6 %}
        {% assign newContent  = newContent | append: l %}
    {% endif %}
{% endfor %}
{{ newContent | markdownify }}

source: https://github.com/biojs/biojs.net/blob/gh-pages/gsoc/includes/ideas.md
page: http://biojs.net/gsoc/2015/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants