Created
August 16, 2020 19:06
-
-
Save hobelinm/c7249acf3c20b09228a5911aa00483b0 to your computer and use it in GitHub Desktop.
Bootstrap Carousel Short-code with support for language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{/* carousel "en" "My Caption" "photo1" "photo2" "photoN" */}} | |
{{ $captionId := replace (replace (.Get 1) " " "") "," "" }} | |
{{ $caption := .Get 1 }} | |
{{ $numOfParams := len .Params }} | |
<div> | |
<div id="{{ $captionId }}" class="carousel slide carousel-fade" data-ride="carousel"> | |
<ol class="carousel-indicators"> | |
{{ range $idx, $item := (seq $numOfParams) }} | |
{{ if ge $idx 2 }} | |
{{ $target := sub $idx 2 }} | |
<li data-target="#{{ $captionId }}" data-slide-to="{{ $target }}" class="{{ if gt $target 0 }}{{else}}active{{ end }}"></li> | |
{{ end }} | |
{{ end }} | |
</ol> | |
<div class="carousel-inner"> | |
{{ range $idx, $item := (seq $numOfParams) }} | |
{{ if and (ge $idx 1) (lt $idx (sub $numOfParams 1)) }} | |
{{- $src := $.Get . }} | |
{{ $target := sub $idx 1 }} | |
<div class="carousel-item {{ if gt $target 0 }}{{else}}active{{ end }}"> | |
<img src="{{ $src }}" class="d-block w-100" alt="{{ $caption }}"> | |
</div> | |
{{ end }} | |
{{ end }} | |
</div> | |
<a class="carousel-control-prev" href="#{{ $captionId }}" role="button" data-slide="prev"> | |
<span class="carousel-control-prev-icon" aria-hidden="true"></span> | |
<span class="sr-only">{{if .Get 0 | eq "en" }}Previous{{ else }}Anterior{{ end }}</span> | |
</a> | |
<a class="carousel-control-next" href="#{{ $captionId }}" role="button" data-slide="next"> | |
<span class="carousel-control-next-icon" aria-hidden="true"></span> | |
<span class="sr-only">{{if .Get 0 | eq "en" }}Next{{ else }}Siguiente{{ end }}</span> | |
</a> | |
</div> | |
<p style="text-align: center; font-style: italic;">{{.Get 1}}</p> | |
</div> | |
<br> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment