Copied to clipboard

Flag this post as spam?

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


  • Arthur Rogel 7 posts 27 karma points
    Jun 17, 2011 @ 16:32
    Arthur Rogel
    0

    Using Image via Parameter

    Hello!

    I'm new to Umbraco, here's what I need to accomplish. I have a macro created to show an image that is picked via a Media Picker propertie in the page. That is working fine. Now, i have to change this Macro to allow de Id of the Media Picker to be passed via paremeter, is that possible?

    Thanks a lot.

    Arthur Rogel

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jun 19, 2011 @ 21:44
    Kim Andersen
    0

    Hi Arthur

    You can grab a paremeter and put the value in a variable like this:

    <xsl:variable name="myVar" select="umbraco.library:Request('nameOfParameter')" />

    If the media id is passed through a paramater in the URL you can just change your id in your current code with the $myVar. Does that make sense to you?

    /Kim A

  • Arthur Rogel 7 posts 27 karma points
    Jun 21, 2011 @ 16:58
    Arthur Rogel
    0

    Hi Kim

    Thanks for your answer.

    The thing is, the media is selected by the editor in the content section, so my macro reads a MediaPicker in the content and shows the image. I managed to pass some parameters to the Macro, but i couldn't get the media Id of a MediaPicker which name is passed via parameter to the macro. Do you have any idea that might help me achieve that? Here's some sample to what i tried to do:

    <!--The parameter image is passed as "imagem"-->
    <
    xsl:param name="image" select="/macro/image" />
    <xsl:variable name="mediaId" select="concat('number($currentPage/',$image,')')" /> 
    <!--The code above does not work, but when I use it like it is bellow, it works-->
           <xsl:variable name="mediaId" select="$currentPage/imagem" />

    I need to do that coz I'll need to use this macro in my page several times, each one showing a different image.

    Thanks a lot,

     

    Arthur Rogel 

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jun 21, 2011 @ 17:30
    Kim Andersen
    0

    Hi Arthur

    Could you try the following code:

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

    The above code should print out the path to the image if the image-parameter contains a media id.

    But if you just want to be able to select multiple media nodes maybe you should take a look at the multinode tree picker form the uComponents project.

    /Kim A

     

    EDIT: Just updated the example with the second parameter in the call to GetMedia :)

  • Arthur Rogel 7 posts 27 karma points
    Jun 21, 2011 @ 17:45
    Arthur Rogel
    0

    Thanks again, Kim!

    When I tried to do as you have suggested, I found an error that was very easily solved, the function GetMedia expects two parameters. After I put the second parameter in its call, I got another error, that i posted bellow.

    Error occured

    System.OverflowException: Value was either too large or too small for an Int32. 
    at System.Convert.ToInt32(Double value) 
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) 
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType) 
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args) 
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer) 
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results) 
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

    Do you have any idea that might help me solve this error? When I replace the "$imageId" inside the call to the function GetMedia for any hard coded number, the error stopped happening.

    Thanks once again,

    Arthur Rogel

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jun 21, 2011 @ 17:48
    Kim Andersen
    0

    Ahh sorry, I was a bit to fast there - sorry about forgetting the second parameter in the GetMedia call :)

    But you might want to check if the $imageId has a value. Like this:

    <xsl:variablename="imageId"select="/macro/image"/>
    <xsl:iftest="$imageId!=''">
        <xsl:value-of select="umbraco.library:GetMedia($imageId,0)/umbracoFile"/>
    </xsl:if>

    /Kim A

  • Arthur Rogel 7 posts 27 karma points
    Jun 21, 2011 @ 19:16
    Arthur Rogel
    0

    Hey, Kim, thanks again for the help.

    With this check, the xslt file was save without any problem, however an error is shown when accessing the published web page (Error parsing XSLT file: \xslt\Images.xslt). I think that's because the GetMedia method expects the id of the media object and i'm passing the name of the MediaPicker propertie in the parameter. Do you know any way to pass the id of the media via parameter?

    Thanks a lot and sorry for the trouble,

    Arthur Rogel

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jun 21, 2011 @ 20:14
    Kim Andersen
    0

    Yeah, you need to give the id of a media node in the GetMedia extension. But wasn't the id in the parameter caled image?

    Which data type are you using as the parameter type on the macro?

    /Kim A

  • Arthur Rogel 7 posts 27 karma points
    Jun 21, 2011 @ 20:20
    Arthur Rogel
    0

    No, the parameter image is a string that represents the name of the MediaPicker object. I include a code sample bellow do explain it better.

    <!-- MediaPicker object -->  
    <umbraco:Item field="imagem" visible="false" runat="server"></umbraco:Item>
    <!-- Macro, with the parametr image passed as the name of the MediaPicker object. -->  
    <umbraco:Macro Alias="Images" image="imagem" runat="server"></umbraco:Macro>

    Thanks a lot,

    Arthur Rogel

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jun 21, 2011 @ 20:34
    Kim Andersen
    0

    Ohh, so you are sending the parameter through the macro n your template. Then I guess that the imagem is the alias of a media picker on your current page? If that's the case then could you try this piece of code:

    <xsl:variablename="imageAlias"select="/macro/image"/>
    <xsl:variable name="imageId" select="$currentPage/*[name()=$imageAlias]" />
    <xsl:iftest="$imageId!=''">
        <xsl:value-of select="umbraco.library:GetMedia($imageId,0)/umbracoFile"/>
    </xsl:if>

    Does this make a difference?

    /Kim A

  • Arthur Rogel 7 posts 27 karma points
    Jun 21, 2011 @ 20:40
    Arthur Rogel
    0

    Thanks a lot, man, that solved my problem!

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jun 21, 2011 @ 21:15
    Kim Andersen
    0

    Cool! I'm very glad to hear that Arthur. Your welcome.

    If I may ask, what are you trying to achieve? You just want to insert multiple images on the same page? Or do you have some different media pickers  that you'll render the content from or what?

    /Kim A

  • Arthur Rogel 7 posts 27 karma points
    Jun 21, 2011 @ 21:18
    Arthur Rogel
    0

    I just need to insert multiple images in the same page, that will be choosen in multiple media pickers. I figured this would be the easiest way to do this, am I wrong?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jun 21, 2011 @ 22:18
    Kim Andersen
    0

    If you just want to be able to select multiple media files I would for sure use the multi node tree picker from uComponents. Here you'll get a nodepicker that can select multiple nodes. Sounds like a perfect tool for your job :)

    Of course only if you want to try it out, otherwise just move on with the solution that you've got already since it's working :)

    Ohh and by the way, could you mark an answer in this post as the solution so that everyone else can see that this question has been solved.

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft