Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-07-07 13:21:49

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Captions with article_image?

I thought outputting a hero image with a caption via article_image would be straight forward, but I can’t seem to manage it.

Apparently article_image and image_info tags do not communicate well. I can’t figure out how to get type="caption" info working in relation to article_image. I realize the attribute doesn’t work with the tag, oddly, so what’s the trick to achieve the end?

My crude lump of clay so far, which seems logical on the surface, but…

<txp:if_article_image>
  <figure>
    <txp:article_image />
    <figcaption><txp:image_info escape="tidy,textile" /></figcaption>
  </figure>
</txp:if_article_image>

Last edited by Destry (2020-07-07 13:23:31)

Offline

#2 2020-07-07 13:26:26

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Captions with article_image?

Are you missing type="caption" ?

Offline

#3 2020-07-07 13:29:36

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: Captions with article_image?

michaelkpate wrote #324341:

Are you missing type="caption" ?

I think that’s supposed to be the default condition if not declared.

But I’m getting the error:

‘Image tags cannot be used outside an image context.’

But I don’t see how it’s not in context.

Offline

#4 2020-07-07 13:42:31

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Captions with article_image?

Destry wrote #324342:

But I don’t see how it’s not in context.

Because the <txp:article_image/> tag is self-closing. It just outputs the image and leaves. Thus, when Txp sees the <txp:image_info> tag without an ID or name, it just shrugs and goes what image?

It might be handy one day to allow <txp:article_image> to be a container. But until that day you need to wrap it in <txp:images> if you want additional info, because that tag defaults to loading up info about the article image in its container:

<txp:if_article_image>
  <figure>
    <txp:images>
      <txp:article_image />
      <figcaption><txp:image_info escape="tidy,textile" /></figcaption>
    </txp:images>
  </figure>
</txp:if_article_image>

EDIT: alternatively, grab the ID of the article image and pass that to the <txp:image_info> tag, in lieu of wrapping it in <txp:images>:

<figcaption><txp:image_info id='<txp:custom_field name="article_image" />' escape="tidy,textile" /></figcaption>

Last edited by Bloke (2020-07-07 13:45:32)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2020-07-07 13:50:03

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Captions with article_image?

Edit; Stef was ahead of me.

I used to get that a lot – especially when I was trying to do things with <smd_thumbnail>.

Try:

<txp:if_article_image>
    <txp:images>
        <figure>
            <txp:article_image />
            <figcaption><txp:image_info escape="tidy,textile" /></figcaption>
        </figure>
    </txp:images>
</txp:if_article_image>

While seemingly redundant it always seemed to fix the problem for me.

Offline

#6 2020-07-07 13:52:03

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: Captions with article_image?

Thanks, the images wrapper. Doh.

Last edited by Destry (2020-07-07 13:52:24)

Offline

#7 2020-07-07 14:00:38

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Captions with article_image?

I suspect that <txp:article_image /> inside <txp:images /> in article context could be problematic for multiple article images. It should be safer to replace it by <txp:image />.

Offline

#8 2020-07-07 14:01:05

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Captions with article_image?

michaelkpate wrote #324344:

<txp:images> While seemingly redundant

In this instance, I agree it does appear redundant. Not entirely sure what we can do about this, though.

We could make the assumption that if you’re wrapping statements in <txp:if_article_image> that you’re likely to be using the article image inside it. Thus we could perhaps preload the article image (at the expense of a database call) into the ‘image container’ ($thisimage) in this special case. That would mean Destry’s OP code would work as-is because the act of including the wrapped conditional would set the context, instead of having to force the context with the default behaviour of <txp:images>.

Not sure if that would have any ramifications on other tags like thumbnail, or plugins inside the conditional.

Perhaps the safer alternative would be to allow <txp:article_image> to be used as a container. It would mean that a bunch of its attributes such as height, width and thumbnail become redundant if used as a container, but there are other tags that behave in this way so it’s not without precedent.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2020-07-07 14:03:28

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Captions with article_image?

etc wrote #324346:

I suspect that <txp:article_image /> inside <txp:images /> in article context could be problematic for multiple article images.

I agree and was going to mention this in my post but saw you mentioned it here. <txp:image> is definitely safer.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#10 2020-07-07 14:06:02

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Captions with article_image?

Bloke wrote #324347:

Perhaps the safer alternative would be to allow <txp:article_image> to be used as a container. It would mean that a bunch of its attributes such as height, width and thumbnail become redundant if used as a container, but there are other tags that behave in this way so it’s not without precedent.

+1

Offline

#11 2020-07-07 14:08:04

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Captions with article_image?

etc wrote #324349:

+1

Core is your oyster ;)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#12 2020-07-07 14:14:40

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Captions with article_image?

Bloke wrote #324350:

Core is your oyster ;)

July is not a month with ‘r’ :-) Anyway, it would seemingly become just a poor map to <txp:images />.

Offline

Board footer

Powered by FluxBB