Skip to content

Commit

Permalink
Add shortcode to show multiple images
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoshiharu Yamashita committed Jul 30, 2017
1 parent 6378e9a commit 307ad99
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,33 @@ paginate = 10

## Shortcodes

### Positional
### fluid_imgs

```
{{< fluid_imgs
"class|src|alt"
"class|src|alt"
"... and so on"
>}}
```

where each positional parameter is separated by the vertical bar (i.e., |).

- `class`: specifies a Pure CSS unit class name (**required**)
- `src`: specifies the URL of an image (**required**)
- `alt`: specifies an alternate text for an image (optional)

See [here](http://yoshiharuyamashita.com/post/hugo-shortcode-to-show-multiple-images/) for examples.

### fluid_img (obsolete)

#### Positional

```
{{% fluid_img "/path/to/img" %}}
```

### Named
#### Named

```
{{% fluid_img class="pure-u-1-2" src="/path/to/img" alt="img description" %}}
Expand Down
21 changes: 21 additions & 0 deletions layouts/shortcodes/fluid_imgs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{ $paramCount := len .Params }}
{{ if gt $paramCount 0 }}
<div class="pure-g">
{{ range $param := .Params }}
{{ $items := split $param "|" }}
{{ $itemCount := len $items }}
<!-- Item count must be at least 2 as
"class" and "src" must be specified -->
{{ if ge $itemCount 2 }}
<div class="{{ index $items 0 }}">
<div style="padding: 0 .2em">
<img
class="pure-img-responsive"
src="{{ index $items 1 }}"
alt="{{ if ge $itemCount 3 }}{{ index $items 2 }}{{ else }}{{ "" }}{{ end }}">
</div>
</div>
{{ end }}
{{ end }}
</div>
{{ end }}

0 comments on commit 307ad99

Please sign in to comment.