Question

I have added a field on my model for specifying where the thumbnail should crop from, but I can't seem to add that to the template tag.

Here is how I do it now:

  {% if entry.main_image.crop_value == "center" %}
   {% thumbnail entry.main_image.image "350x100" crop="center" as im %}
        <a href="{{ entry.get_absolute_url }}"><img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" alt=""></a>
    {% endthumbnail %}
  {% elif entry.main_image.crop_value == "top" %}
   {% thumbnail entry.main_image.image "350x100" crop="top" as im %}
        <a href="{{ entry.get_absolute_url }}"><img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" alt=""></a>
    {% endthumbnail %}
  {% elif entry.main_image.crop_value == "bottom" %}
   {% thumbnail entry.main_image.image "350x100" crop="bottom" as im %}
        <a href="{{ entry.get_absolute_url }}"><img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" alt=""></a>
    {% endthumbnail %}
  {% endif %}

This can't be the best way of doing it?

Was it helpful?

Solution

You can use the variable in the template tag:

{% thumbnail entry.main_image.image "350x100" crop=entry.main_image.crop_value as im %}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top