1

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.

Lukas Liesis
  • 24,652
  • 10
  • 111
  • 109

1 Answers1

0

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

DC.Azndj
  • 1,346
  • 12
  • 13