Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow inclusion of other content in a content file #247

Closed
iwishicouldcode opened this issue Apr 1, 2014 · 19 comments
Closed

Allow inclusion of other content in a content file #247

iwishicouldcode opened this issue Apr 1, 2014 · 19 comments

Comments

@iwishicouldcode
Copy link

A not-uncommon use case for me is the need to reuse content (say a set of links, or a particular FAQ or etc.)

I know one could create a layout for this, but that seems hacky and unintuitive. It would be nice if content files could contain something like {{% "name_of_simple_layout_file" "path_to_some_other_content_file" %}} that would render the mentioned content file with some layout, then include the result.

What do you think?

@spf13
Copy link
Contributor

spf13 commented Apr 1, 2014

Happy to take a pull request for this.

You would need to create a template function like the list here…
https://github.com/spf13/hugo/blob/master/template/bundle/template.go#L161

which would take a template and content file as input, then render them.

Perhaps call it RenderContent(TemplateName, ContentFile)

We may want a new template type for these reusable snippets/block/whatever we call them

Once that function is written, then we would need to expose it via a custom short code so we can use it in the content files. 

A good example of this is the highlight short code, defined here
https://github.com/spf13/hugo/blob/master/template/bundle/embedded.go#L22

Best,
Steve

-- 
Steve Francia
http://stevefrancia.com
http://spf13.com
http://twitter.com/spf13

From: iwishicouldcode notifications@github.com
Reply: spf13/hugo reply@reply.github.com
Date: April 1, 2014 at 11:19:15 AM
To: spf13/hugo hugo@noreply.github.com
Subject:  [hugo] Allow inclusion of other content in a content file (#247)

A non-uncommon use case for me is the need to reuse content (say a set of links, or a particular FAQ or etc.)

I know one could create a layout for this, but that seems hacky and unintuitive. It would be nice if content files could contain something like {{% "name_of_simple_layout_file" "path_to_some_other_content_file" %}} that would render the mentioned content file with some layout, then include the result.

What do you think?


Reply to this email directly or view it on GitHub.

@cburgdorf
Copy link
Contributor

This looks like something I may would like to put my hands on.

@jorinvo
Copy link
Contributor

jorinvo commented Oct 2, 2014

See #534

I tried to build a flexible shortcode.
It should allow you to just write {{% content link="/posts/first/" %}} in your markdown and render another content.
There is just a problem in the moment that in some cases the indentation gets interpreted as code and highlighted..

@chibicode
Copy link

👍

@bep
Copy link
Member

bep commented Aug 22, 2015

@cabello did you "put your hands on this"?

@cabello
Copy link
Contributor

cabello commented Dec 28, 2015

@bep I have not but I am not sure I am the person you intended to message.

@bep
Copy link
Member

bep commented Dec 28, 2015

@cabello you are correct ... I think @cburgdorf raised his hands ...

@bep
Copy link
Member

bep commented Feb 28, 2017

This issue has been automatically marked as stale because it has not been commented on for at least four months.

The resources of the Hugo team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, and you feel that it is still valuable, please open a proposal at https://discuss.gohugo.io/.

This issue will automatically be closed in four months if no further activity occurs. Thank you for all your contributions.

@bep bep added the Stale label Feb 28, 2017
@bep
Copy link
Member

bep commented Mar 1, 2017

Note/Update: This issue is marked as stale, and I may have said something earlier about "opening a thread on the discussion forum". Please don't.

If this is a bug and you can still reproduce this error on the latest release or the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.

@digitalcraftsman
Copy link
Member

A shortcode with the readFile and markdownify template functions should solve this problem.

@bep bep closed this as completed Mar 24, 2017
@stevenbriscoeca
Copy link

stevenbriscoeca commented Nov 6, 2017

Anyone that stumbles across this issue this is what I did and it seems to work great :

shortcodes/content.html

{{$file := .Get 0}}
{{ with .Site.GetPage "page" "documentation" $file }}{{ .Content | markdownify }}{{ end }}

Markdown file :
{{% content "file.md" %}}

@ctron
Copy link

ctron commented Apr 18, 2018

I think including content out of the box, without adding any shortcodes, is a valuable addition for a site generator tool.

@kaushalmodi
Copy link
Contributor

@ctron A site generator can only do so much. It's the limitation of the markup language you choose rather than the site generator.

Markdown doesn't have a syntax for including whole file contents. But Org mode does.

But then, what's wrong with adding a shortcode to get around that Markdown limitation? Please continue this discussion to the Hugo Discourse forum if you are interested.

@ctron
Copy link

ctron commented Apr 18, 2018

Well I don't think using a short code is wrong. I just think that it should be provided as a standard short code. Like gist or instagram.

@amarder
Copy link

amarder commented Jul 10, 2019

I'm using a slight modification of @StephenBe's solution:

{{$file := .Get 0}}
{{ $file | readFile | markdownify }}

One thing to note, the paths passed to the shortcode should be relative to the /content/ folder.

@jcyrss
Copy link

jcyrss commented Dec 28, 2019

I'm using a slight modification of @StephenBe's solution:

{{$file := .Get 0}}
{{ $file | readFile | markdownify }}

One thing to note, the paths passed to the shortcode should be relative to the /content/ folder.

The big problem of this way is , the headings of included markdown file will NOT be put into the TOC, that's too bad.

@crisrojas
Copy link

I'm using a slight modification of @StephenBe's solution:

{{$file := .Get 0}}
{{ $file | readFile | markdownify }}

One thing to note, the paths passed to the shortcode should be relative to the /content/ folder.

Works great but it also renders the yaml, is there a way to make it ignore it?

 2020-06-08 at 13 19 44

@davidsneighbour
Copy link
Contributor

@crisrojas there is a help forum at discourse.gohugo.io.

And if you use the original, not the "slightly modified" version of the code that was shown AFTER the issue was closed three years ago then the yaml is not parsed and displayed. Use .Content.

#247 (comment)

Please don't comment on closed issue. Just refer to them in the forum.

@github-actions
Copy link

github-actions bot commented Feb 1, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests