Skip to content

Commit 6510221

Browse files
committed
refactor image once more to be easier to maintain and fix bug: "{{ image }} shortcode issues"
1 parent a78b266 commit 6510221

1 file changed

Lines changed: 18 additions & 59 deletions

File tree

layouts/shortcodes/image.html

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,22 @@
1010
{{ $width_mobile = .Get "width_mobile" }}
1111
{{ end }}
1212

13-
{{ if .Get "image3" }}
1413
<div class="row mb-5 align-items-center" id={{ .Get "id" }}>
15-
<!-- image1 -->
16-
{{ $image1 := .Get "image1" | relURL }}
17-
{{ $alt1 := .Get "alt1" | relURL }}
18-
{{ $caption1 := .Get "caption1" | relURL }}
19-
<div class="col-lg-{{ $width_desktop }} col-{{ $width_mobile }} center-block ">
20-
{{ if .Get "link1" }}
21-
<a href={{ .Get "link1" }} target="_blank">
22-
{{ end }}
23-
<img src={{ .Get "image1" }} alt={{ .Get "alt1" }} title={{ .Get "caption1" }}> </img>
24-
{{ if .Get "link1" }}
25-
</a>
26-
{{ end }}
27-
</div>
28-
<!-- /image1 -->
29-
<!-- image2 -->
30-
{{ $image2 := .Get "image2" | relURL }}
31-
{{ $alt2 := .Get "alt2" | relURL }}
32-
{{ $caption2 := .Get "caption2" | relURL }}
33-
<div class="col-lg-{{ $width_desktop }} col-{{ $width_mobile }} center-block ">
34-
{{ if .Get "link2" }}
35-
<a href={{ .Get "link2" }} target="_blank">
36-
{{ end }}
37-
<img src={{ .Get "image2" }} alt={{ .Get "alt2" }} title={{ .Get "caption2" }}> </img>
38-
{{ if .Get "link2" }}
39-
</a>
40-
{{ end }}
41-
</div>
42-
<!-- /image2 -->
43-
<!-- image3 -->
44-
{{ $image3 := .Get "image3" | relURL }}
45-
{{ $alt3 := .Get "alt3" | relURL }}
46-
{{ $caption3 := .Get "caption3" | relURL }}
47-
<div class="col-lg-{{ $width_desktop }} col-{{ $width_mobile }} center-block ">
48-
{{ if .Get "link3" }}
49-
<a href={{ .Get "link3" }} target="_blank">
50-
{{ end }}
51-
<img src={{ .Get "image3" }} alt={{ .Get "alt3" }} title={{ .Get "caption3" }}> </img>
52-
{{ if .Get "link3" }}
53-
</a>
54-
{{ end }}
55-
</div>
56-
<!-- /image3 -->
57-
<!-- image4 -->
58-
{{ $image4 := .Get "image4" | relURL }}
59-
{{ $alt4 := .Get "alt4" | relURL }}
60-
{{ $caption4 := .Get "caption4" | relURL }}
61-
<div class="col-lg-{{ $width_desktop }} col-{{ $width_mobile }} center-block ">
62-
{{ if .Get "link4" }}
63-
<a href={{ .Get "link4" }} target="_blank">
64-
{{ end }}
65-
<img src={{ .Get "image4" }} alt={{ .Get "alt4" }} title={{ .Get "caption4" }}> </img>
66-
{{ if .Get "link4" }}
67-
</a>
68-
{{ end }}
69-
</div>
70-
<!-- /image4 -->
71-
</div>
72-
{{ end }}
14+
{{ range (seq 1 4)}}
15+
{{ if $.Get (print "image" .) }}
16+
{{ $image := $.Get (print "image" .) | relURL }}
17+
{{ $alt := $.Get (print "alt" .) | relURL }}
18+
{{ $caption := $.Get (print "caption" .) | relURL }}
19+
{{ $link := $.Get (print "link" .) | relURL }}
20+
<div class="col-lg-{{ $width_desktop }} col-{{ $width_mobile }} center-block ">
21+
{{ if $link }}
22+
<a href={{ $link }} target="_blank">
23+
{{ end }}
24+
<img src={{ $image }} alt={{ $alt }} title={{ $caption }}> </img>
25+
{{ if $link }}
26+
</a>
27+
{{ end }}
28+
</div>
29+
{{ end }}
30+
{{ end }}
31+
</div>

0 commit comments

Comments
 (0)