Copied to clipboard

Flag this post as spam?

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


  • Matthew 93 posts 153 karma points
    Jun 13, 2012 @ 00:27
    Matthew
    0

    another passing parameters question - 2nd try

    Sorry for the dupe, first one blew up.

    I have a page with ~15 images, each in a property: fig1; fig2; fig3; etc. I'm trying to create a macro with a parameter so I can just change the figure property for each instance I place on the template.

    This razor script with no parameter works:

    Template:
    <umbraco:Macro Alias="ShowFigure" runat="server"></umbraco:Macro>

    Script:
    <a href="@Library.MediaById(Model.fig1).umbracoFile">
    <img src="/imagegen.ashx?width=550&[email protected](Model.fig1).umbracoFile" alt="" />
    </a>

    If I add a text parameter 'figure' to the macro, and input 'fig1' when inserting the macro into the template, plus replace 'fig1' with 'figure' in the script, it does not work:

    Template:
    <umbraco:Macro figure="fig1" Alias="ShowFigure" runat="server"></umbraco:Macro>

    Script:
    <a href="@Library.MediaById(Model.figure).umbracoFile">
    <img src="/imagegen.ashx?width=550&[email protected](Model.figure).umbracoFile" alt="" />
    </a>

    The page shows the ImageGen 'Hello, world!' error, and the source shows no image:

    <img src="/imagegen.ashx?width=550&image=" alt="" />

    However, if I put <p>@Parameter.figure</p> in the script, it shows the parameter contents correctly, 'fig1' (w/o quotes), on the webpage, so I know it's getting there.

    I think I've tried all the possible combinations of "" and [], plus tossing in an occasional '#' for good measure, in both the template/parameter and the script but haven't figured out the magic.

    Help!

     

  • Barry Fogarty 493 posts 1129 karma points
    Jun 13, 2012 @ 07:17
    Barry Fogarty
    0

    Is it not simply

    /imagegen.ashx?width=550&[email protected](Parameter.figure).umbracoFile" alt="" />

    ?

    Also not sure if this matters but I normally use the MediaById razor extension in this way:

    @Model.MediaById(id).umbracoFile

    EDIT:  After re-reading I'm not sure this will work - my assumption was you are passing in @Model.fig1 (or whichever one you need) as the parameter called figure.  Basically you want that parameter to hold the media ID of the image you are trying to render - then the above code will work.

  • Matthew 93 posts 153 karma points
    Jun 13, 2012 @ 07:45
    Matthew
    0

    Thanks for the reply.  I ended up using GetPropertyValue instead of MediaById after I thought it through a bit and realised the parameter I was passing wasn't an ID at all.  And thanks for the clarification of 'MediaById', it's not easy finding clarity.

Please Sign in or register to post replies

Write your reply to:

Draft