Docs: Fix resize_image and gallery shortcodes (#1543)

This commit is contained in:
Avinash Sonawane 2021-07-07 09:08:37 +00:00 committed by GitHub
parent ee85300303
commit 96e28ddd5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 11 deletions

View file

@ -127,7 +127,8 @@ but it can be used in Markdown using [shortcodes](@/documentation/content/shortc
The examples above were generated using a shortcode file named `resize_image.html` with this content:
```jinja2
<img src="{{ resize_image(path=path, width=width, height=height, op=op) }}" />
{% set image = resize_image(path=path, width=width, height=height, op=op) %}
<img src="{{ image.url }}" />
```
## Creating picture galleries
@ -143,14 +144,16 @@ This can be used in shortcodes. For example, we can create a very simple html-on
picture gallery with the following shortcode named `gallery.html`:
```jinja2
{% for asset in page.assets %}
{% if asset is matching("[.](jpg|png)$") %}
<a href="{{ get_url(path=asset) }}">
<img src="{{ resize_image(path=asset, width=240, height=180, op="fill") }}" />
<div>
{% for asset in page.assets -%}
{%- if asset is matching("[.](jpg|png)$") -%}
{% set image = resize_image(path=asset, width=240, height=180) %}
<a href="{{ get_url(path=asset) }}" target="_blank">
<img src="{{ image.url }}" />
</a>
&ensp;
{% endif %}
{% endfor %}
{%- endif %}
{%- endfor %}
</div>
```
As you can notice, we didn't specify an `op` argument, which means that it'll default to `"fill"`. Similarly,

View file

@ -1,7 +1,10 @@
<div>
{% for asset in page.assets -%}
{%- if asset is matching("[.](jpg|png)$") -%}
<a href="{{ get_url(path=asset) | safe }}" target="_blank">
<img src="{{ resize_image(path=asset, width=240, height=180, op="fill", format="auto") | safe }}" />
{% set image = resize_image(path=asset, width=240, height=180) %}
<a href="{{ get_url(path=asset) }}" target="_blank">
<img src="{{ image.url }}" />
</a>
{%- endif %}
{%- endfor %}
</div>

View file

@ -1 +1,2 @@
<img src="{{ resize_image(path=path, width=width, height=height, op=op) }}" />
{% set image = resize_image(path=path, width=width, height=height, op=op) %}
<img src="{{ image.url }}" />