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 a template function to process strings with shortcodes in them. #6094

Open
zivbk1 opened this issue Jul 18, 2019 · 7 comments

Comments

@zivbk1
Copy link
Contributor

commented Jul 18, 2019

With a frontmatter variable like:

biography = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sed nunc vitae turpis eleifend tincidunt. In hac habitasse platea dictumst. {{< figure src="/media/spf13.jpg" title="Steve Francia" >}} Pellentesque viverra a tellus in mollis. Sed vitae congue odio, vitae tristique magna. Mauris id fermentum libero, sit amet ultricies metus. "

Provide a template function shortcodify that will render the figure shortcode into the output string.

This would allow shortcodes to be used in frontmatter data, within data file content, and expand the capabilities of Hugo for pages that require more than one 'content' block. See the Sawmill layout technique for an example of this use case, which is already supported by the Forestry.io CMS.

@bep bep added the Proposal label Jul 19, 2019
@bep

This comment has been minimized.

Copy link
Member

commented Jul 19, 2019

Provide a template function shortcodify that will render the figure shortcode into the output string.

Shortcodify? :-)

The shortcode's API requires a Page, so it couldn't be used in data files, and I think the "more than one content" block needs to be solved differently. I have plans for that. We could possibly, maybe adjust the shortcode's API to allow different things, and make this somehow work, but that is a rather big change and will need more than one person needing it.

@bwklein

This comment has been minimized.

Copy link

commented Jul 19, 2019

Yeah, I was trying to follow the naming model of some of the other functions. 😄 Call it whatever you like, I really just want the ability to convert a shortcode in the string into the HTML (or whatever) in the shortcode template.

I didn't realize there was a requirement of a Page, I assumed that it was more of a converter that took some shortcode name and the (positional or named) variables passed into the process, and replaced that shortcode call into the resulting output based on whatever was in the Shortcode file.

I am a bit surprised that more people haven't run into this yet. The Sawmill method makes page building so easy for people. Setting up design components (blocks) of the page and then letting the editor build a page from those components without requiring a developer to build a special layout for every possible combination of blocks the editor might want. It does treat front matter like a little content database, but that seems reasonable.

I would like to know more about your plans for dealing with the need to support more than one content block. That might make this request irrelevant.

If you want to see the project that I am working on and where I have run into this issue, I'd be happy to show you. I don't think my use of Hugo or modular design elements is too far off the beaten path.

@zivbk1

This comment has been minimized.

Copy link
Contributor Author

commented Jul 19, 2019

I would like to have something in my templates like this to process the string and get what I want out of it. {{ .Section.biography | shortcodify | markdownify }}

The shortcodes in the string would be rendered and then the output string of that function would pipe into the markdownify function to convert any markdown in the string to HTML.

That's the hopes and dreams I have at the moment. 😄

@regisphilibert

This comment has been minimized.

Copy link

commented Jul 21, 2019

and will need more than one person needing it

Including @zivbk1, @budparr and I, that's a miminum of 3 😄, but I suspect this will grow to most users by the end of the year as more and more clients/editors are getting used to page builders.

When building a page with blocks of data, most of those are saved as Front Matter. It then falls on the developer to range on those blocks and apply the proper data processing/partial loading etc...

In the context of a very nice to have page builder, Hugo shortcodes are currently unusable by the editor and any search-and-replace workaround cooked up by developers (been there) will never match the reliability and usability of Hugo's shortcode API.

The shortcode's API requires a Page, so it couldn't be used in data files,

Fine by me.

@nicfits

This comment has been minimized.

Copy link

commented Jul 22, 2019

I'm using the Sawmill approach for our clients, and confirm this would be a useful feature for our editors.

@johndmulhausen

This comment has been minimized.

Copy link

commented Oct 9, 2019

Absolutely want this feature, see https://discourse.gohugo.io/t/call-shortcodes-in-markdownified-text/21189 for context. @regisphilibert - got any examples of the search/replace method?

@regisphilibert

This comment has been minimized.

Copy link

commented Oct 9, 2019

@johndmulhausen I answered in your thread.

The shortcode's API requires a Page

@bep This could simply be a required parameter on the newly introduced shortcodify function. So we always end up with a page.

{{/* layouts/_default/single.html */}}
{{ range .blocks }}
  <div class="text">
   {{ shortcodify .content $ }}
  </div>
{{ end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.