First of all, i'm new to xslt and umbraco. I am trying to create a image gallery, which i can place in a article/page by inserting a macro. The macro has an mediaCurrent which i want to select the mediafolder to list images from. Is this possible ? I have tryed several things but cannot get it to work. Can someone help me in the right direction ?
So far i have this code, after many trial and errors:
You can definitely achieve what you want - you are on the right track ;-)
Without investigating your source in detail it seems you have an issue with your media id's. I have a similar snippet you can use for inspiration here.
Image gallery macro
Hi.
First of all, i'm new to xslt and umbraco.
I am trying to create a image gallery, which i can place in a article/page by inserting a macro. The macro has an mediaCurrent which i want to select the mediafolder to list images from. Is this possible ? I have tryed several things but cannot get it to work. Can someone help me in the right direction ?
So far i have this code, after many trial and errors:
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="mediafoldersource" select="/macro/mediafoldersource"/>
<xsl:template match="/">
<xsl:variable name="mediaId" select="umbraco.library:GetXmlNodeById($mediafoldersource)/self::node" />
<div class="ImageGallery">
<ul>
<xsl:if test="count($mediaId/data) > 0 and string($mediaId/data[@alias='umbracoFile']) != ''">
<xsl:for-each select="umbraco.library:GetMedia($mediaId)/self::node">
<xsl:choose>
<xsl:when test="@nodeTypeAlias = 'Image'">
<li>
<a>
<xsl:attribute name="href">
<xsl:value-of select="umbraco.library:GetMedia(@id, 'false')/data [@alias = 'umbracoFile']"/>
</xsl:attribute>
<xsl:attribute name="rel">
<xsl:value-of select="string('colorbox')"/>
</xsl:attribute>
<img>
<xsl:attribute name="src">
<xsl:value-of select="Exslt.ExsltStrings:replace(umbraco.library:GetMedia(@id, 'false')/data [@alias = 'umbracoFile'], '.', '_thumb.')"/>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="@nodeName"/>
</xsl:attribute>
</img>
</a>
</li>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:if>
</ul>
</div>
</xsl:template>
Hi Mattis, welcome to the forum.
You can definitely achieve what you want - you are on the right track ;-)
Without investigating your source in detail it seems you have an issue with your media id's. I have a similar snippet you can use for inspiration here.
I hope it helps.
>Tommy
Hi Tommy :)
Thank you very much for your reply, this pointed me in the right direction and I ended up with this.
<xsl:param name="currentPage"/> <xsl:variable name="MediaNodeId" select="/macro/MediaNode/node/@id"/> <xsl:template match="/"> <div class="ImageGallery"> <ul> <xsl:if test="$MediaNodeId != '' "> <!-- just added as cast-workaround --> <xsl:for-each select="umbraco.library:GetMedia($MediaNodeId, '0')/node"> <xsl:if test="@nodeTypeAlias='Image'"> <li> <a> <xsl:attribute name="href"> <xsl:value-of select="umbraco.library:GetMedia(@id, '0')/data [@alias = 'umbracoFile']"/> </xsl:attribute> <xsl:attribute name="rel"> <xsl:value-of select="string('colorbox')"/> </xsl:attribute> <img> <xsl:attribute name="src"> <xsl:value-of select="Exslt.ExsltStrings:replace(umbraco.library:GetMedia(@id, 'false')/data [@alias = 'umbracoFile'], '.', '_thumb.')"/> </xsl:attribute> <xsl:attribute name="alt"> <xsl:value-of select="@nodeName"/> </xsl:attribute> </img> </a> </li> </xsl:if> </xsl:for-each> </xsl:if> </ul> </div> </xsl:template>I'm glad you got it working.
>Tommy
Hi,
We have just releases Simpleviewer for Umbraco, available at http://our.umbraco.org//projects/website-utilities/simpleviewer-package-for-umbraco .
With this package you can use the www.simpleviewer.net gallery and pick the images from your media folder without writing a single line of code.
regards,
Pau
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.