include image rendition conditional
  • Hi all,

    I tried to get a conditional to check if there is a image/thumb/etc. defined, and if not, i want to display a placeholder for each _tpl/img/img_XxY.tpl.
    No success was with $image->defined.
    Which is the recommended way, always display an specific image if e.g. {{ include file="_tpl/img/img_250x167.tpl" where="front-bottom" }} is chosen.

    Thanks for your help in advance.
    Thomas.

  • 8 Comments sorted by
  • Please tell me as well where the placeholder images should be saved on webserver.
  • Hi,
    to check if rendition exists, you can use this 

    {{ capture name="_img" assign="_img" }}
    {{ image rendition="articlebig" }}
                  <figure class="clearall">
                      <img src="{{ $image->src }}" width="{{ $image->width }}" height="{{ $image->height }}" class="tencol last" rel="resizable" style="max-width: 100%" alt="{{ $image->caption }} (photo: {{ $image->photographer }})" />
                      <figcaption class="clearall">
                          <em>{{ $image->caption }}</em>
                      </figcaption>
                  </figure>
    {{ /image }}
    {{ /capture }}

    {{ if trim($_img) }}{{ $_img }}{{ else }}...}{{ /if }}

    In this example, {{ capture }} captures processed code and assigns it to variable; then you only need to check if variable is empty or not.
    --
    Ljuba Rankovic
    Senior Front End Developer, Sourcefabric
    ljuba.rankovic@sourcefabric.org

    http://www.sourcefabric.org
    http://www.twitter.com/Sourcefabric
  • Hi Ljuba,

    Might is be possible to check {{ if ! $gimme->article->image->thumbnailurl }} ? Or wont there be an thumbnail?

    Where should placeholder pictures being placed ? (or referenced) - which is the <img src="{{ xxx }}"> path, when placing images below current template, e.g. /themes/publication_1/theme_1/_img/ (which variable contains /themes/publication_1/theme_1/_img/ ) ?
  • You can put placeholder images anywhere inside your theme's folder, for
    example /img. Accessing them is easy with {{ uri
    static_file="img/placeholder.jpg" }}

    Best, Ljuba

    On Monday, 11 June 2012, BAUMANN Thomas wrote:

    > Hi Ljuba,
    >
    > Might is be possible to check {{ if ! $gimme->article->image->thumbnailurl
    > }} ? Or wont there be an thumbnail?
    >
    > Where should placeholder pictures being placed ? (or referenced) - which
    > is the path, when placing images below current template, e.g.
    > /themes/publication_1/theme_1/_img/ (which variable contains
    > /themes/publication_1/theme_1/_img/ ) ?
    >
    >
    --
    Ljuba Rankovic
    Senior Front End Developer, Sourcefabric
    ljuba.rankovic@sourcefabric.org

    http://www.sourcefabric.org
    http://www.twitter.com/Sourcefabric
  • Hi Ljuba, I did this, but the placeholder is not being resized.
    How could this being solved?

    I think of something like:

                    <figure{{ if $where == "author" }} class="fourcol"{{ /if }}>
                        <a{{ if $where == "section" }} class="fourcol"{{ /if }} href="{{ url options="article" }}">
                            <img src="{{ uri static_file="img/placeholder.png" }} " width="{{ $image->width }}" height="{{ $image->height }}" rel="resizable" style="max-width: 100%" alt="{{ $image->caption }} (photo: {{ $image->photographer }})" />
                        </a>
                    </figure>

    How is the <figure class="XXX"> being created, as currently is gets not filled by "class=threecol" or "class=eightcol" ?


    Best regards,
    Thomas.
    Post edited by BAUMANN Thomas at 2012-06-12 12:31:41
  • The class is very important, as it has to be inherited by the above class, so it must not be static.
  • Hi,
    in this case class applied to <figure> is created when variable $where has value 'author', and this value is forwarded from parent template (let's say article.tpl) to this included template like this
    {{ include file="img/img_600x400.tpl" where="author" }}
    --
    Ljuba Rankovic
    Senior Front End Developer, Sourcefabric
    ljuba.rankovic@sourcefabric.org

    http://www.sourcefabric.org
    http://www.twitter.com/Sourcefabric
  • Perfect. Thank you.
    Post edited by BAUMANN Thomas at 2012-06-17 15:06:33