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: The examples above were generated using a shortcode file named `resize_image.html` with this content:
```jinja2 ```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 ## 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`: picture gallery with the following shortcode named `gallery.html`:
```jinja2 ```jinja2
{% for asset in page.assets %} <div>
{% if asset is matching("[.](jpg|png)$") %} {% for asset in page.assets -%}
<a href="{{ get_url(path=asset) }}"> {%- if asset is matching("[.](jpg|png)$") -%}
<img src="{{ resize_image(path=asset, width=240, height=180, op="fill") }}" /> {% set image = resize_image(path=asset, width=240, height=180) %}
<a href="{{ get_url(path=asset) }}" target="_blank">
<img src="{{ image.url }}" />
</a> </a>
&ensp; {%- endif %}
{% endif %} {%- endfor %}
{% endfor %} </div>
``` ```
As you can notice, we didn't specify an `op` argument, which means that it'll default to `"fill"`. Similarly, 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 -%} {% for asset in page.assets -%}
{%- if asset is matching("[.](jpg|png)$") -%} {%- if asset is matching("[.](jpg|png)$") -%}
<a href="{{ get_url(path=asset) | safe }}" target="_blank"> {% set image = resize_image(path=asset, width=240, height=180) %}
<img src="{{ resize_image(path=asset, width=240, height=180, op="fill", format="auto") | safe }}" /> <a href="{{ get_url(path=asset) }}" target="_blank">
<img src="{{ image.url }}" />
</a> </a>
{%- endif %} {%- endif %}
{%- endfor %} {%- 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 }}" />