Lorem ipsum shortcode for Hugo?

Requirement: In Ruby (I am moving from Middleman to Hugo) there are a number of wonderful plugins for generating Lorum Ipsum text, in any amount of paragraphs, words, headings, subheadings etc. ( https://loremipsum.io/plugins/ ) I might be wrong but there does not seem to be an equivalent for Hugo. I created a crude shortcode called Lorem to do just that and though it now has parameters returning differing lengths, my advanced abilities regarding sophisticated shortcodes in Hugo are basically zero.

Question: Is there anything like a Lorem shortcode or implementation out there for Hugo?

Suggested feature: It would be very useful if such a feature is included as a shortcode within Hugo.

Any pointers will be appreciated.

I think your request, while useful, does not fit as a Hugo’s built-in shortcode. Those are supposed to be either widely used of help enforce consistency in the way certain aspect of the websites are implemented (opengraph etc…)

I would suggest you create a set of shortcodes and/or partials doing just that and bundle them in a “theme component”. This would allow any other Hugo user out there to easily add them to their project, use them in developement, and remove them once in production (as I suppose those will not be useful there)

If you need help building those shortcodes, please ask in the discourse, many would gladly welcome this shortcode bundle and help you I’m sure!

Thanks, it makes sense.

@casperl – You got me curious, and turns out the seq function comes in handy here.

Let’s say you wanted to generate 20 paragraphs of lorem text.


{{< loremGen 20 >}}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse accumsan rutrum consectetur. Vivamus eu ex quis leo posuere convallis. Nunc laoreet velit sed ullamcorper mollis. Mauris porta consequat tortor aliquet maximus. Quisque sed purus condimentum orci sodales aliquam non vel tellus. Praesent lorem arcu, scelerisque a semper at, iaculis eget purus. Etiam ullamcorper orci a porttitor sodales. Nullam tincidunt nibh et hendrerit auctor. Quisque vitae quam ut lorem vehicula condimentum. In commodo cursus elit, non volutpat lectus sagittis non.</p>
{{</ loremGen >}}


{{ $times := .Get 0 }}
{{ $lorem := .Inner }}

{{ range seq $times }}
  {{ $lorem | safeHTML }}
{{ end }}

Try this:

{{- $count := .Get "count" | default (.Get 0) | default 1 -}}
{{- $loremipsum := slice "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur." "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." -}}
{{- range seq $count}}
<p class="loremipsum">
    {{- range $index := seq 0 (index (shuffle (seq 0 3) ) 0 ) -}}
    {{ index $loremipsum $index }}&nbsp;
    {{- end -}}
{{- $loremipsum = shuffle $loremipsum -}}
{{- end -}}

It starts off with a standard “Lorem ipsum …” and then randomises the sentence order on each subsequent paragraph - I have no idea if it makes sense. :wink:


Hi @chrisallmark,

Welcome to this community! If you don’t mind, I’d like to publish a theme component with your code.

1 Like

Sure, no problem.

1 Like

BTW: There was a small bug in it as {{< loremipsum >}} wasn’t displaying anything so I’ve added a default of 1 paragraph.


Enjoy! And thanks for your permission.