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

Add .RenderShortcodes #7297

Closed
bep opened this issue May 20, 2020 · 9 comments · Fixed by #11320
Closed

Add .RenderShortcodes #7297

bep opened this issue May 20, 2020 · 9 comments · Fixed by #11320

Comments

@bep
Copy link
Member

bep commented May 20, 2020

I have been hit by this issue twice recently -- so I assume this is a problem worth solving (I know there are similar issue, and this also relates to .RenderString.

Currently we have:

  • .Content which gives rendered HTML with shortcodes rendered.
  • .RawContent which gives the raw source excluding front matter. No shortcodes rendered.

A common pattern is to include files using .GetPage via a shortcode, e.g.:

# Title

{{< include "foo.md" >}}

Using the {{< means you can include just about anything and it will be preserved as-is. But it will not partake in the global rendering context re. table of contents, foot notes etc.

You can do this in your shortcode:

{{ (site.GetPage "foo.md").RawContent n}}

And then

# Title

{{% include "foo.md" %}}

The above will work but any shortcodes in foo.md will not be rendered.

Which this issue is all about.

I assume that it makes sense that .RenderString uses this method internally by default, but what I need is basically:

{{ $markdownWithRenderedShortcodes := .RawContent | .RenderShortcodes }}

These should also work:

{{ $markdownWithRenderedShortcodes := .RenderShortcodes }}
{{ $markdownWithRenderedShortcodes := "string with shortcodes" | .RenderShortcodes }}

/cc @regisphilibert @onedrawingperday @digitalcraftsman @moorereason and gang

And yes, this is tightly connected to a Page so I think a method makes sense.

@bep bep added the Proposal label May 20, 2020
@stale
Copy link

stale bot commented Sep 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. 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 relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Sep 20, 2020
@bep bep added the Keep label Sep 20, 2020
@stale stale bot removed the Stale label Sep 20, 2020
@theory
Copy link
Contributor

theory commented Oct 10, 2020

Would this feature, if implemented, render the shortcodes for the current output format? That'd be super great!

@bep
Copy link
Member Author

bep commented Oct 10, 2020

Yes.

@blattersturm
Copy link

Is this going to get implemented at all any time soon? People keep asking how to build my PR and since no equivalent functionality exists in mainline and @bep outright rejected my PR likely as they felt this was a better way to implement this (and therefore it became the only implementation they'd accept, apparently) I don't have any actual alternative option to get shortcodes processed in JSON output.

@davidsneighbour
Copy link
Contributor

Checking your PR it was rejected not outright for a feeling but for missing formalities. Open an issue, describe and discuss your issue, then if it is deemed a good addition to hugo open a PR referencing that issue number.

@jmooring
Copy link
Member

A need for this came up again yesterday:
https://discourse.gohugo.io/t/export-to-markdown-with-shortcodes/39590

@Rumperuu
Copy link

Rumperuu commented Aug 1, 2023

This came up again as the potential solution to a forum issue I posted: https://discourse.gohugo.io/t/table-of-contents-render-hook/45352

@bep bep mentioned this issue Aug 1, 2023
4 tasks
bep added a commit to bep/hugo that referenced this issue Aug 1, 2023
A layouts/shortcodes/include.html shortcode may look like this:

```html
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
```

Fixes gohugoio#7297
bep added a commit to bep/hugo that referenced this issue Aug 1, 2023
A layouts/shortcodes/include.html shortcode may look like this:

```html
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
```

Fixes gohugoio#7297
@bep bep added Enhancement and removed Proposal labels Aug 1, 2023
@bep bep added this to the v0.117.0 milestone Aug 1, 2023
bep added a commit to bep/hugo that referenced this issue Aug 2, 2023
A layouts/shortcodes/include.html shortcode may look like this:

```html
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
```

Fixes gohugoio#7297
bep added a commit to bep/hugo that referenced this issue Aug 3, 2023
A layouts/shortcodes/include.html shortcode may look like this:

```html
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
```

Fixes gohugoio#7297
bep added a commit to bep/hugo that referenced this issue Aug 3, 2023
A layouts/shortcodes/include.html shortcode may look like this:

```html
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
```

Fixes gohugoio#7297
@bep bep closed this as completed in #11320 Aug 3, 2023
bep added a commit that referenced this issue Aug 3, 2023
A layouts/shortcodes/include.html shortcode may look like this:

```html
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
```

Fixes #7297
@theory
Copy link
Contributor

theory commented Aug 5, 2023

Tried it out, works great, thanks!

@github-actions
Copy link

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 Aug 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants