Use parameter as html-tag

Is it possible to pass html-tag I want to use in shortcode in shortcode parameter?
Like this:

{{< section
section-bg-color=“second-accent-color”
title="<h1>We know our work well, let us prove it to you!</h1>"
title-text-align=“center”
title-font-size=“36”
title-color=“white” >}}
title-tag=“h2” >}}
{{< /section >}}

<{{ .Get "title-tag"}} class="title {{ with .Get "title-font-size"}}title_fz_{{.}} {{ end }} {{ with .Get "title-text-align"}}title_ta_{{.}} {{ end }} {{ with .Get "title-color"}}title_c_{{.}} {{ end }}"> {{ .Get "title" | safeHTML }} </{{ .Get "title-tag"}}>
1 Like

It should work, have you come up with an error while testing that code?

There is an error while building project http://prntscr.com/lno3ck .

Alright, let’s take it back two steps please. What are you trying to accomplish?

What have you done so far and what command did you run to get that error?
it looks to be a gulp error and not something related to Hugo.

You had syntax errors, among other things:

  • There is no need to provide a shortcode closing tag, {{< /section >}}, since you are not passing .Inner
  • The quotes from your snippet were some weird character, so converted them to normal double quotes
  • Lastly, why are you nesting a h1 instead a h2? Yes, the below works… but it is not good HTML

I’ll leave it to you to fix from here, good luck.

Definition:

{{ $titleTag := .Get "title-tag" }}
{{ $titleFontSize := .Get "title-font-size" }}
{{ $titleTextAlign := .Get "title-text-align" }}
{{ $titleColor := .Get "title-color" }}
{{ $title := .Get "title" }}

{{ printf "<%s class=\"title title_fz_%s title_ta_%s title_c_%s\">%s</%s>" $titleTag $titleFontSize $titleTextAlign $titleColor $title $titleTag | safeHTML }}

Usage:

{{< section
section-bg-color="second-accent-color"
title="<h1>We know our work well, let us prove it to you!</h1>"
title-text-align="center"
title-font-size="36"
title-color="white"
title-tag="h2" >}}
1 Like