Skip to content

Commit

Permalink
Add popup parameter for figure include (#3119)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnScottUK authored May 5, 2024
1 parent adae207 commit 162f659
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions _includes/figure
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<figure class="{{ include.class }}">
{%- if include.popup -%}<a href="{{ include.image_path | relative_url }}" class="image-popup" title="{% if include.caption %}{{ include.caption | markdownify | remove: "<p>" | remove: "</p>" }}{% endif %}">{%- endif -%}
<img src="{{ include.image_path | relative_url }}"
alt="{% if include.alt %}{{ include.alt }}{% endif %}">
{%- if include.popup -%}</a>{%- endif -%}
{%- if include.caption -%}
<figcaption>
{{ include.caption | markdownify | remove: "<p>" | remove: "</p>" }}
Expand Down
9 changes: 6 additions & 3 deletions docs/_docs/14-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,23 @@ Generate a `<figure>` element with a single image and caption.
| **image_path** | **Required** | Full path to image eg: `/assets/images/filename.jpg`. Use absolute URLS for those hosted externally. |
| **alt** | Optional | Alternate text for image. |
| **caption** | Optional | Figure caption text. Markdown is allowed. |
| **popup** | Optional | Wrap the image as a popup link using class `image-popup` |

Using the `figure` include like so:

```liquid
{% raw %}{% include figure image_path="/assets/images/unsplash-image-10.jpg" alt="this is a placeholder image" caption="This is a figure caption." %}{% endraw %}
{% raw %}{% include figure popup=true image_path="/assets/images/unsplash-image-10.jpg" alt="this is a placeholder image" caption="This is a figure caption." %}{% endraw %}
```

Will output the following:

{% include figure image_path="/assets/images/unsplash-image-10.jpg" alt="this is a placeholder image" caption="This is a figure caption." %}
{% include figure popup=true image_path="/assets/images/unsplash-image-10.jpg" alt="this is a placeholder image" caption="This is a figure caption." %}

```html
<figure>
<img src="/assets/images/unsplash-image-10.jpg" alt="this is a placeholder image">
<a href="/assets/images/unsplash-image-10.jpg" class="image-popup" title="This is a figure caption.">
<img src="/assets/images/unsplash-image-10.jpg" alt="this is a placeholder image">
</a>
<figcaption>This is a figure caption.</figcaption>
</figure>
```
Expand Down

0 comments on commit 162f659

Please # to comment.