Copied to clipboard

Flag this post as spam?

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


  • Jan 54 posts 74 karma points
    Apr 21, 2010 @ 10:35
    Jan
    0

    Making a macro with <a href - img link - using the individual pages media picker

    Hello there - newcomer to umbraco.

     

    I have been having good luck with making macros that post out the page name of a page - showing the link easily.

    now i have a page where each indiviual page have a specific IMG (button) that is picked in a media picker

    how would i go about making so that a pages individual media picker - is set as the <a href when the macro makes all the links.

     

    any help appreciated.

     

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 21, 2010 @ 10:48
    Lee Kelleher
    1

    Hi Jan, welcome to the Umbraco community!

    First advice would be to read over the following articles, they will familiarise you with the GetMedia function.

    http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia

    http://blog.leekelleher.com/2009/11/30/how-to-use-umbraco-library-getmedia-in-xslt/

     

    If you get stuck and need some advice, copy-n-paste your XSLT code (either small snippet or full template) and we can help your figure out (and understand) the problem.

    Good luck, Lee.

  • Jan 54 posts 74 karma points
    Apr 21, 2010 @ 11:38
    Jan
    0

    thanx for quick response lee.

    im terrible with the macros there - only using the basic default ones for umbraco.

    I use the macro to list out each page under the current page.

    Mainpage Excomm
          page 1 news
          page 2 contact

    with the simple default used from umbraco.

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
      <xsl:if test="umbraco.library:HasAccess(@id, @path) = true()">    
          <a href="{umbraco.library:NiceUrl(@id)}">
            <xsl:value-of select="@nodeName"/>
          </a>
      </xsl:if>
    </xsl:for-each>


    each page has a property (ExcommKnap) a media picker.

    and i managed to make this here that i can use to pull out the image onto a normal template - while tying a class from stylesheet.
    i would like to get this into the macro somehow.

    how do i specify that it has to use (ExcommKnap) in my macro and then print out the image as such (with class from stylesheet)

     <umbraco:Item runat="server" field="excommknap" xslt="concat('&lt;img class=&quot;ExcommKnap&quot; src=&quot;', umbraco.library:GetMedia({0},'true')/data[@alias='umbracoFile'], '&quot;alt=&quot;', umbraco.library:GetMedia({0},'true')/data[@alias='umbracoFile'], '&quot;/&gt;')" xsltDisableEscaping="true" />

    sorry if im not making much sense - im having hard time wrapping my brain around this here
              

  • Rasmus Berntsen 215 posts 253 karma points c-trib
    Apr 21, 2010 @ 13:31
    Rasmus Berntsen
    1

    Written from the top of my head... :)

    <img class="ExcommKnap">

    <xsl:attribute name="src">

    <xsl:value-of select="umbraco.library:GetMedia(data[@alias='excommknap'], 0)/data [@alias = 'umbracoFile']"/>

    </xsl:attribute>

    </img>

     

  • Rasmus Berntsen 215 posts 253 karma points c-trib
    Apr 21, 2010 @ 13:33
    Rasmus Berntsen
    0

    And you should be added in the for-each loop if I understand you correctly...

  • Jan 54 posts 74 karma points
    Apr 21, 2010 @ 14:46
    Jan
    0

    i tried your suggestion.

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">

       <xsl:attribute name="src">
          <xsl:value-of select="umbraco.library:GetMedia(data[@alias='excommknap'], 0)/data [@alias = 'umbracoFile']"/> 
       </xsl:attribute>

    </xsl:for-each>
    </ul>

    </xsl:template>

    but it wrote out a error list.

    (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    ved Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    ved System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
    ved System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
    ved System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    ved umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

  • Rasmus Berntsen 215 posts 253 karma points c-trib
    Apr 21, 2010 @ 14:50
    Rasmus Berntsen
    1

    Don't know if it's the problem but you're missing the img-tag and the LI's inside of your UL. Like this:

    <ul>
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">

    <li>

    <img>  

    <xsl:attribute name="src">
          <xsl:value-of select="umbraco.library:GetMedia(data[@alias='excommknap'], 0)/data [@alias = 'umbracoFile']"/> 
       </xsl:attribute>

    </img>

    </li>

    </xsl:for-each>
    </ul>

  • Jan 54 posts 74 karma points
    Apr 21, 2010 @ 15:36
    Jan
    0

    this is whats written in the macro now - still shows a error

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
     version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:msxml="urn:schemas-microsoft-com:xslt"
     xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:umbraco.contour="urn:umbraco.contour"
     exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <ul>
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">

    <li>

    <img>  

    <xsl:attribute name="src">
          <xsl:value-of select="umbraco.library:GetMedia(data[@alias='excommknap'], 0)/data [@alias = 'umbracoFile']"/> 
       </xsl:attribute>

    </img>

    </li>

    </xsl:for-each>
    </ul>


    </xsl:template>

    </xsl:stylesheet>

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 21, 2010 @ 16:01
    Lee Kelleher
    0

    Hi Jan,

    Thanks to Berntsen's suggestions, you are so close... but to help you understand the XSLT a little better, I have added a few comments.

    Try this:

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="msxml umbraco.library">
        <xsl:output method="xml" omit-xml-declaration="yes"/>
    
        <xsl:param name="currentPage"/>
    
        <xsl:template match="/">
            <!-- first, check if you have any 'nodes', otherwise you'll get an empty <ul/> tag -->
            <xsl:if test="count($currentPage/node[string(data[@alias='umbracoNaviHide']) != '1']) &gt; 0">
                <ul>
                    <!-- loop through each of the pages 'nodes' -->
                    <xsl:for-each select="$currentPage/node[string(data[@alias='umbracoNaviHide']) != '1']">
                        <li>
                            <!-- check if the 'media picker' property has a value -->
                            <xsl:if test="data[@alias='excommknap'] != ''">
                                <!-- get the media XML and assign it to a variable -->
                                <xsl:variable name="media" select="umbraco.library:GetMedia(number(data[@alias='excommknap']), 0)" />
                                <!-- check if the media XML contains an image path 'umbracoFile' -->
                                <xsl:if test="count($media/data[@alias='umbracoFile']) &gt; 0">
                                    <img class="ExcommKnap" src="{$media/data[@alias='umbracoFile']}" />
                                </xsl:if>
                            </xsl:if>
                        </li>
                    </xsl:for-each>
                </ul>
            </xsl:if>
        </xsl:template>
    </xsl:stylesheet>

    I keep going back to my blog post about how to deal with the GetMedia function safely, this is what is happening... First when dealing with a loop, especially a <ul> list, it is important to check if there are any <node>s to loop through, otherwise you end up with an empty <ul /> tag - which causes all sorts of rendering problems in various browsers!

    Once you are inside your loop, check if the current page/node has a value for the media-picker - otherwise there is no point in calling GetMedia - as it will return nothing ... or worse, an error.

    After you get back the XML data from GetMedia, then check if it has any data in the 'umbracoFile' property, then display accordingly.

    I can appreciate that XSLT is overwhelming to Umbraco newcomers - so I wouldn't expect you to "get it" straight away! Things will make more sense over time. My advice is always check that the data is there before you try to display it.

    Cheers, Lee.

    PS. If you are planning on coming to CG10, there'll be a session on basic XSLT techniques (as well as more medium-2-advanced techniques).

  • Jan 54 posts 74 karma points
    Apr 21, 2010 @ 17:09
    Jan
    0

    ok awesome - i put this in and it works now - added a border ="0" to remove the ugly box around it :P

    now on to whole new problems how to make a mouse over effect using a secondary picture :)

    <?xml version="1.0" encoding="utf-8"?><!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]><xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:msxml="urn:schemas-microsoft-com:xslt"
            xmlns:umbraco.library="urn:umbraco.library"
            exclude-result-prefixes="msxml umbraco.library">
           <xsl:output method="xml" omit-xml-declaration="yes"/>
            <xsl:param name="currentPage"/>
            <xsl:template match="/">
                    <!-- first, check if you have any 'nodes', otherwise you'll get an empty <ul/> tag -->
                    <xsl:if test="count($currentPage/node[string(data[@alias='umbracoNaviHide']) != '1']) &gt; 0">
                                    <!-- loop through each of the pages 'nodes' -->
                                    <xsl:for-each select="$currentPage/node[string(data[@alias='umbracoNaviHide']) != '1']">
                                                    <!-- check if the 'media picker' property has a value -->
                                                    <xsl:if test="data[@alias='excommknap'] != ''">
                                                            <!-- get the media XML and assign it to a variable -->
                                                            <xsl:variable name="media" select="umbraco.library:GetMedia(number(data[@alias='excommknap']), 0)" />
                                                            <!-- check if the media XML contains an image path 'umbracoFile' -->
                                                            <xsl:if test="count($media/data[@alias='umbracoFile']) &gt; 0">
                                                            <a href="{umbraco.library:NiceUrl(@id)}">
                                                               <img class="ExcommKnap" src="{$media/data[@alias='umbracoFile']}" border="0" />
                       </a>
                                                            </xsl:if>
                                                    </xsl:if>
                                    </xsl:for-each>
                    </xsl:if>
            </xsl:template>
    </xsl:stylesheet>

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 21, 2010 @ 19:26
    Lee Kelleher
    0

    Hi Jan,

    Glad that it worked and happy to help.

    Not sure what you want to achieve exactly, but it sounds like you need some basic HTML/JavaScript tutorials, try some of the following:

    http://www.google.com/search?q=HTML+image+rollover

    http://www.w3schools.com/js/js_animation.asp

    http://www.howtocreate.co.uk/tutorials/jsexamples/testingRoll.html

    They should give you a good start.  I'd suggest that you get your desired effects working in a standalone/separate HTML file - so that you don't get confused with the XSLT parts of it (or Umbraco in general) ... mixing up technologies from the start is confusing!

    If we can help with any specific Umbraco problems, let us know!

    Good luck, Lee.

  • Rasmus Berntsen 215 posts 253 karma points c-trib
    Apr 21, 2010 @ 20:51
    Rasmus Berntsen
    1

    ... And you should really move the border="0" to your stylesheet.

    img.ExcommKnap{border:none;}

    :)

  • Jan 54 posts 74 karma points
    Apr 22, 2010 @ 18:14
    Jan
    0

    i was trying to make a simple <a href><img></a> link . that pulled the image from a page . so hen a page is made in content - you add a button of your choice to that page - and the link shows the image.

    i fixed the For each to show from the root always - itht hat current setup it vanished when you went into a page since it was a current page it checked for nodes.

     

    if theres a better way - cleaner way - do let know.  for now im trying to see if i can make it a css effect on the picture with mouse over - chaning the alpha level or something like that.

    i am awfully new to this heh. thanx for hose turtorials ill go through them

     

  • Rasmus Berntsen 215 posts 253 karma points c-trib
    Apr 22, 2010 @ 20:54
    Rasmus Berntsen
    0

    How does your node-structure look like? Listing all nodes from root is not best practice. You should create a structure like this:

    -Home

    --Subpage

    --Subpage

    And then you should list all nodes like this:

     

    <xsl:variable name="level" select="1"/>

     

        <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">

    That way you will go to the node at level 1 and list all nodes below, in the example above that would be the two subpages. :)

Please Sign in or register to post replies

Write your reply to:

Draft