Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Includes

Tags:

jekyll

I've seen some posts saying you can only pass literal strings to Jekyll's front matter include statement like so:

{% include mypage.ext %}

However, I have the following HTML layout for pretty much every page:

    <section id="feature">
        <div class="container_12">
            <div class="grid_12 alpha omega">
                {% include myfile.ext %}
            </div>
        </div>
    </section>

    <section id="main">
        <div class="container_12">
            <div class="grid_12 alpha omega">
                {{ content }}
            </div>
        </div>
    </section>

This would be painful to have to include in every single page in order to achieve the layout I'm looking for. The included file would be relevant to the current page, so I was hoping someone knew of some kind of way to do this. Of course it'd be something along the lines of:

{% include {{page.file}} %}

I've seen some other posts saying this just can't happen though.

So, I just want to be able to dynamically load includes in Jekyll.

Edit: https://github.com/mojombo/jekyll/issues/176

like image 446
Kezzer Avatar asked Jul 02 '12 20:07

Kezzer


People also ask

What is sling dynamic include?

Sling Dynamic Include is actually a way of using Server Side Includes in Apache Sling (or CQ5). Whenever SDI finds an include, it will replace it with a SSI tag, so the include will be done by the http server and not by the sling engine.

What is the first step in enabling SDI in dispatcher in AEM?

Configure SDI As a first step load the mod_include.so module through httpd. conf or the configuration file that loads the modules.

How does Apache Sling work?

Apache Sling™ is a framework for RESTful web-applications based on an extensible content tree. In a nutshell, Sling maps HTTP request URLs to content resources based on the request's path, extension and selectors.


2 Answers

This will be perhaps possible when that issue will be fixed with the pull request #1495 which propose exactly what you are looking for : {% include {{page.file}} %}

like image 165
Anthony O. Avatar answered Oct 07 '22 17:10

Anthony O.


This is currently intentionally not possible, as the maintainers of Jekyll don't want the project to get too dynamic. You can read this comment & thread for a bit of background. The suggestion that qrush (the maintainer) gives is to use rails or sinatra. Probably not the answer you're looking for, but that's the current status.

If you want to use a plugin, there's one that will let you do this here

like image 40
QRohlf Avatar answered Oct 07 '22 17:10

QRohlf