hugo-universal-theme icon indicating copy to clipboard operation
hugo-universal-theme copied to clipboard

Use shortcodes from original universal theme

Open cale-inspired opened this issue 8 years ago • 9 comments

Hey there,

first off, thanks for porting the universal theme. I love it, currently setting up my new website with it. I was wondering which is the best way to use the shortcodes from universal theme, e.g. the accordion text boxes. Shall I create shortcuts for them as well? But how am I supposed to feed it with data then, the only idea I could think of would be using .Params.whatever, but that doesn't seem elegant to me. Any other ideas?

cale-inspired avatar Aug 15 '16 21:08 cale-inspired

Hi there,

Thank you for using it :)

I believe we would like to include these shortcodes within the content of any page or post. In this case, as you mentioned, adding them via .Params doesn't look like a good idea.

I think Hugo shortcodes are the way to go since they are designed to render text to HTML code. For example, to use an alert we could do something like:

{{% alert info %}}This is an info alert.{{% /alert %}}

And the shortcode implementation would be something like this:

<div class="alert alert-{{ .Get 0 }}" role="alert">
{{ .Inner }}
</div>

And it would be rendered as:

<div class="alert alert-info" role="alert">
This is an info alert.
</div>

I haven't tested this example, it's just a draft of what I think is the right direction.

Let me know what you think.

adrianmo avatar Aug 18 '16 13:08 adrianmo

@inspiritana any thoughts?

adrianmo avatar Sep 07 '16 08:09 adrianmo

I think I agree with the idea @adrianmo , it's pretty much the whole point of them in my opinion.

GeorgeWL avatar Jul 04 '17 13:07 GeorgeWL

This is also what I'm hinting at in #101.

ringods avatar Jul 31 '17 19:07 ringods

@cale-inspired @GeorgeWL @adrianmo can you have a look at PR #104 and chime in on the discussion?

ringods avatar Aug 03 '17 07:08 ringods

trying this out, but wher will you define the alert class, and how ?

jcolomb avatar Aug 23 '22 14:08 jcolomb

could not make it to work, using https://www.w3schools.com/w3css/w3css_alerts.asp instead with card.html in the Shortcodes folder:

<div class="w3-card-4">

<header class="w3-container w3-lime w3-hover-amber">
  <h1>{{ .Get 0 }}</h1>
</header>

<div class="w3-container w3-lime ">
  <p>{{ .Inner | markdownify | emojify }}</p>
</div>

</div>

jcolomb avatar Aug 24 '22 09:08 jcolomb

Also added the expand Shortcodes (taken from the learn theme), only need to add expand.html:

{{ $_hugo_config := `{ "version": 1 }` }}
<div class="expand">
    <div class="expand-label" style="cursor: pointer;" onclick="$h = $(this);$h.next('div').slideToggle(100,function () {$h.children('i').attr('class',function () {return $h.next('div').is(':visible') ? 'fas fa-chevron-down' : 'fas fa-chevron-right';});});">
        <i style="font-size:x-small;" class="fas fa-chevron-right"></i>
        <span>
        {{$expandMessage := T "Expand-title"}}
    	{{ if .IsNamedParams }}
    	{{.Get "default" | default $expandMessage}}
    	{{else}}
    	{{.Get 0 | default $expandMessage}}
    	{{end}}
    	</span>
    </div>
    <div class="expand-content" style="display: none;">
        {{.Inner | safeHTML}}
    </div>
</div>

jcolomb avatar Aug 24 '22 09:08 jcolomb

Could do a PR if you like.

jcolomb avatar Aug 24 '22 09:08 jcolomb