Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 Yesterday 22:48:31

mwr
Member
From: Canada
Registered: 2006-01-31
Posts: 170
Website

article_image alt

Is there an easy way to add alt to article_image? I thought <txp:article_image alt=“icon for <txp:title />” /> might work.


Mark

Offline

#2 Today 10:11:50

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,241
Website GitHub

Re: article_image alt

As you’ve discovered, alt isn’t an attribute of the article_image tag. You have two options:

You can use the trim and replace tags to “search and replace” the tag string:

<txp:article_image trim='/alt="(.+?)"/' replace='alt="Icon for <txp:title />"' />

The weird-looking use of single quotes for the attributes here is because the double quote is part of the search and replace values (and also because using a tag inside an attribute requires single quotes).

Or you can do:

<txp:if_article_image>
    <txp:images>
        <img src="<txp:image_url />" alt="Icon for <txp:title />">
    </txp:images>
</txp:if_article_image>

which gives you greater flexibility. You can add extra image attributes here if you like using the image_info tag. txp:images tries to be context aware so will use the article image if it’s available. It’s wise to wrap this tag in if_article_image because if no article image is specified it will output all the last ten images if I recall correctly.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB