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
    Sep 17, 2012 @ 07:06
    Matthew
    0

    Get images from other nodes

    I'm trying to render a page with a list of all images (figures) of the same property name ('Fig3', for instance) from selected pages.

    On the content page, using an ultimate picker 'figurePages', I select the pages I want, then enter the media property name I want listed.

    Although this script works, with the figure name 'Fig3' entered manually:

    <ul>

    @foreach (var Node in Model.figurePages.Split(','))

    {
    var curNode = Library.NodeById(Node);

    <p>@curNode.Name @Model.figure</p>

    <img src="@curNode.Media("Fig3","umbracoFile")" width=550 />
    }

    </ul>

    It doesn't if I use the property 'figure' instead, although the @Model.figure in the <p> above shows it has the correct value of 'Fig3':

    <img src="@curNode.Media("figure","umbracoFile")" width=550 />

    I've tried several variations but haven't found the magic jelly bean.  Help?

  • Matthew 93 posts 153 karma points
    Sep 17, 2012 @ 10:21
    Matthew
    0

    Tried adding a variable on top to carry the 'figure' property value inside the loop but that didn't work either...

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
      var fig = @Model.figure;
    ...
    <imgsrc="@curNode.Media("fig","umbracoFile")"width=550/>
    ...

    Nor with @fig either.  Still looking for any help, appreciated.

  • Matthew 93 posts 153 karma points
    Sep 17, 2012 @ 19:24
    Matthew
    0

    And for clarity, entering the property value directly ('Fig4') renders this html:

    <imgsrc="/media/36391/Fig4.png" width=550 /></p>

    But using the property or variable, it does this:

    <imgsrc="" width=550 /></p>

    Also tried republishing the entire site to clear the cache.  Still no love...

  • Matthew 93 posts 153 karma points
    Sep 18, 2012 @ 23:26
    Matthew
    0

    Finally realized from the html that the literal 'Fig3' was providing the path, not the name, so added a var to hold the name and, after much pondering and 1k trials/errors, figured out how to pass it along to the img tag, thusly:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines.Library;
    // get the figure to use
    @{var fig = Model.figure;
    <ul>
     // get a list of content pages to use from the ultimatepicker and split it up
     @foreach (var Node in Model.figurePages.Split(','))
     {
      // get the current node of the foreach loop
      var curNode = Library.NodeById(Node);
      // get the image path from the current node
      var pic = curNode.Media(fig);
      // display the name of the content page that the image comes from
      <p><strong>@curNode.Name</strong><br/>
      // display the image from the var 'pic'
      <img src="@pic.umbracoFile" width=550 />
      </p>
     }
    </ul>
    }

    Hopefully this helps some future dufus.

Please Sign in or register to post replies

Write your reply to:

Draft