Add code file to hugo

What is the easiest way to add a code file to huge?
something like below

the file I am calling from is in content/article/

{{ < code_file ../codes/ > }}

this gets auto-translated to


└── article-1/


{{ (.Page.Resources.GetMatch (.Get 0)).Content }}


{{< get-content >}}

This didn’t worked like I said, I want it to show as code with python highlighting, but it just showed text only :frowning: Also your code don’t work if the file name is not

Start building sites …
hugo v0.87.0+extended darwin/amd64 BuildDate=unknown
Error: Error building site: "$ROOT/content/article/": 
failed to render shortcode "get-content": 
failed to process shortcode: "$ROOT/layouts/shortcodes/get-content.html:1:35": 
execute of template failed: template: shortcodes/get-content.html:1:35: 
executing "shortcodes/get-content.html" at <0>: 
nil pointer evaluating resource.Resource.Content
Built in 4847 ms

That is not what you originally asked for.

Then incorporate the highlight function within the shortcode:


{{ highlight (.Page.Resources.GetMatch (.Get 0)).Content (.Get 1) "linenos=table" }}

And call it like this:

{{< highlight-content python >}}

Page Resources must exist within Page Bundles, either leaf bundles or branch bundles. A leaf bundle is a directory with an file and associated resources.

Thanks a lot.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.