简体   繁体   中英

Jekyll print content of file

I have a file which contains code. I want to place that file in the custom folder and get the source code of it in the post. Is it possible?

Something like this:

{{ 'samples/trafikito.html' | raw }}

So it would read file content and just return whatever is inside.

You could place the sample folder inside the _includes folder. Then, wrap the include tag inside <pre><code> ... </code></pre> . So, it'd look like the following:

# inside _includes/samples/trafikito.html

<div>
    <h1>Test Code<h1>
    <p>Test Code</p>
</div>


================


# inside the file where you want to include the sample

...
<pre>
    <code>
        {% include samples/trafikito.html %}
    </code>
</pre>
...

This works for any source code file type ( .html , .json , etc.) since Jekyll just inserts the full file contents into the destination file. The inserted code is surrounded by tags that tell the browser to render the contents as textual code not as actual code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM