Copied to clipboard

Flag this post as spam?

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


  • Nate 143 posts 184 karma points
    Nov 23, 2010 @ 15:31
    Nate
    0

    Do I need a seperate macro for each image?

    If I have a bunch of content pickers, lets say 100 on a site.  Do I need to write 100 different macros/xslt combos to display each image?

    If not, can someone point me to an example where I shows a reusable macro?

    Thanks!

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Nov 23, 2010 @ 15:36
    Matt Brailsford
    0

    Hi Nate,

    You most certainly don't need 100 different macros/xslt files.

    What you can do is on your macro define a property which you can pass in (say the id of the media item) then in your XSLT you can reference it something like thid (suposing your macro property alias was imageId).

    <?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:variable name="imageId" select="/macro/imageId" />

      <xsl:param name="currentPage"/>

    <xsl:template match="/">
    ...
      </xsl:template>

    </xsl:stylesheet>

    From here, you could then just render it out in the main body of your template:

    <xsl:value-of select="umbraco.library:GetMedia($imageId, 0)/umbracoFile" />

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Nov 23, 2010 @ 15:42
    Matt Brailsford
    0

    For the sake of clarity, you'd then probably have something like this in your template

    <umbraco:Macro alias="myMacroAlias" runat="server" imageId="[#pickerAlias1]" />
    <umbraco:Macro alias="myMacroAlias" runat="server" imageId="[#pickerAlias2]" />
    <umbraco:Macro alias="myMacroAlias" runat="server" imageId="[#pickerAlias3]" />

    [#...] is special syntax in umbraco which tells it to get the value from a property with that alias from the current document.

    Matt

  • Kim Andersen 1447 posts 2197 karma points MVP
    Nov 23, 2010 @ 15:57
    Kim Andersen
    0

    Hi Nate

    Are the pickers on the same page in your installation?

    If you just want to pick let's say 100 different images to be shown the same way in the same page, I'd suggest you take a look at the multiple media picker in the uComponents package.

    With this macro you can pick all the images that you want with just one property instead of 100. Just an idea...

    /Kim A

  • Nate 143 posts 184 karma points
    Nov 24, 2010 @ 04:19
    Nate
    0

    Thank's man, that really helped.  Here's the final XSLT in case anyone else needs to know.  Btw, what's the difference between a variable and a parameter?

     

    <?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="class" select="/macro/class" />
      <xsl:param name="imgAlias" select="/macro/imgAlias" />
      <xsl:param name="cropName" select="/macro/cropName" />
     
      <xsl:param name="currentPage"/>
     
      <xsl:template match="/">
        <img>
           <xsl:attribute name="src">
             <xsl:if test="$imgAlias != '' ">
               <xsl:value-of select="umbraco.library:GetMedia($currentPage/*[local-name()=$imgAlias], false)/imageCropper//crop [@name = $cropName]/@url"/>
             </xsl:if>
           </xsl:attribute>
        
           <xsl:attribute name="class">
             <xsl:value-of select="$class"/>
           </xsl:attribute>
          
        </img>
      </xsl:template>
     
    </xsl:stylesheet>

  • Nate 143 posts 184 karma points
    Nov 24, 2010 @ 04:20
    Nate
    0

    double post...

  • Colin Browne 31 posts 52 karma points
    Nov 29, 2010 @ 17:09
    Colin Browne
    0

    http://msdn.microsoft.com/en-us/library/ms950787.aspx#xml0619_topic1

     

    I found this link to be very helpful in explaining the difference.

Please Sign in or register to post replies

Write your reply to:

Draft