Copied to clipboard

Flag this post as spam?

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


  • Ole Abrahamsen 12 posts 52 karma points
    Mar 22, 2012 @ 09:30
    Ole Abrahamsen
    0

    Issue with Library.MediaById (Razor)

    Hello.

    Screenshots: http://imgur.com/a/b8WL5

    I am trying to select images from a nodes children (first screenshot provided).

    As you can see, the Image child-node contains a text-string (image caption) and a media picker (picking an image from the media folder).

    In the macro (third image), I have tried to dumb it down as much as possible. But, when I try to load the page, I get an error (fourth image). Using ?umbdebug I get the error-message shown in image 5.

    Please advice.

  • Grant Thomas 291 posts 324 karma points
    Mar 22, 2012 @ 09:34
    Grant Thomas
    0

    I'd be very insterested in knowing which namespace you imported to actually be able to even USE @Library - I was looking for this all last night.

    Exactly which Umbraco version are you using?

  • Ole Abrahamsen 12 posts 52 karma points
    Mar 22, 2012 @ 10:00
    Ole Abrahamsen
    0

    v4.7.1.1

    It should be part of the MacroEngines namespace, which is imported already?

    What you see in my Razor-script is the entire script.

  • Ole Abrahamsen 12 posts 52 karma points
    Mar 22, 2012 @ 10:36
    Ole Abrahamsen
    0

    The issue definitely has something to do with Library using Examine to locate(?) the media, but examine not working properly.

    I have not changed any settings regarding Examine however, and I'm puzzled with this behavior.

  • Grant Thomas 291 posts 324 karma points
    Mar 22, 2012 @ 10:57
    Grant Thomas
    0

    Okay, you might not have to use Library directly, does this work for you:

    foreach (var node DynamicModel.Children) {
    <li><a href="@Umbraco.GetMediaUrl(node.image)">@node.Name</a></li>

    Note that I'm dancing between versions here (there are so many breaking changes it's unbelievable), so this is much of a guess.

  • Ole Abrahamsen 12 posts 52 karma points
    Mar 22, 2012 @ 11:01
    Ole Abrahamsen
    0

    Hm, not exactly:

    'The name 'Umbraco' does not exist in the current context'

  • Grant Thomas 291 posts 324 karma points
    Mar 22, 2012 @ 11:11
    Grant Thomas
    0

    Does importing the the namespace, as below, help:

    @using Umbraco.Cms.Web;

    At the top of the file, but below the @inherits specifier.

  • Ole Abrahamsen 12 posts 52 karma points
    Mar 22, 2012 @ 11:21
    Ole Abrahamsen
    0

    No change.

    I tried changing the code a bit:

    @foreach (var node in Model.Children{
       var media Model.GetMediaUrl(1147);
      <li><href="@media">@node.imageCaptionTitle</a></li>
    }

    The Model.GetMediaUrl(1147) (1147 = id of the media file) returns an empty string.

    It doesn't matter whether I use node.image/node.Image or hardcode the ID.

    The node.imageCaptionTitle returns the correct value though.

     

  • Ole Abrahamsen 12 posts 52 karma points
    Mar 22, 2012 @ 11:33
    Ole Abrahamsen
    0

    Hrm. Made it work. Don't really like my solution though, it seems a bit too much trial-and-error-colored. :P

    @foreach (var node in Model.Children{
       string imgPath new Media(Convert.ToInt32(node.Image)).getProperty("umbracoFile").Value.ToString();
      <li><href="@imgPath">@node.imageCaptionTitle</a></li>
    }
  • Rodion Novoselov 694 posts 859 karma points
    Mar 22, 2012 @ 19:25
    Rodion Novoselov
    100

    Hi, Ole. The Library.MediaById should work well this way:

    <a href="@Library.MediaById(item.Image).UmbracoFile">bla-bla-bla</a>

     

Please Sign in or register to post replies

Write your reply to:

Draft