Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mattis 2 posts 22 karma points
    Feb 16, 2010 @ 10:17
    Mattis
    0

    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) &gt; 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>

  • Tommy Poulsen 514 posts 708 karma points
    Feb 16, 2010 @ 11:07
    Tommy Poulsen
    1

    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

  • Mattis 2 posts 22 karma points
    Feb 16, 2010 @ 12:19
    Mattis
    0

    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>

  • Tommy Poulsen 514 posts 708 karma points
    Feb 16, 2010 @ 12:29
    Tommy Poulsen
    0

    I'm glad you got it working.

    >Tommy

  • Pau Storch 4 posts 34 karma points
    May 27, 2011 @ 10:35
    Pau Storch
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft