Matching images to articles
This is an open discussion with 4 replies, filed under Troubleshooting.
Search
You want to look at the key
element and function. This article on dynamic image placement using Symphony covers its use.
The basic idea is that you use the key
element to group all images together according to their entry ID. It's then possible to retrieve a group by using the key
function and passing it the ID to get the images of the corresponding entry.
Absolutely brilliant, thanks Mark you're a genius. It works a treat.
Mark linked back to this post from another thread, so just though I'd post a cut-down version of my code:
<xsl:key name="images-by-entry" match="product-images/entry" use="product/item/@id"/> <xsl:template match="products/entry"> <p> <xsl:for-each select="key('images-by-entry', @id)"> <xsl:if test="position()=1"> <a href="{$workspace}/{image/@path}/{image/filename}"> <img alt="{description}" src="{$root}/image/1/110/110/{image/@path}/{image/filename}" /> </a> </xsl:if> </xsl:for-each> </p> <h2><xsl:value-of select="name"/></h2> <xsl:copy-of select="description/*"/> <h3>£<xsl:value-of select="format-number(price,'#.00')"/></h3> <xsl:if test="count(key('images-by-entry', @id))>1"> <h2>More images:</h2> <p> <xsl:for-each select="key('images-by-entry', @id)"> <xsl:if test="position()>1"> <a href="{$workspace}/{image/@path}/{image/filename}"> <img alt="{description}" src="{$root}/image/1/110/110/{image/@path}/{image/filename}" /> </a> </xsl:if> </xsl:for-each> </p> </xsl:if> </xsl:template>
Hope it helps.
@ m_onkey Thanks for your post, it helps a lot :-)
but I think there's an error where you refer to:
<a href="{$workspace}/{image/@path}/{image/filename}">
it should be:
<a href="{$workspace}{image/@path}/{image/filename}">
without /
after the {workspace}
Create an account or sign in to comment.
I've attached images to a bunch of articles and I'm trying to display a list of the articles with their image (or the first image) alongside.
I can't figure out how to do this, any ideas?
I've got the articles and the article-images into the XML, but when I'm applying templates in the articles nodeset they can no longer see the article-images nodeset and so I'm not sure how to connect the two.
Thanks.