Copied to clipboard

Flag this post as spam?

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


  • Ben Chambers 2 posts 22 karma points
    Apr 20, 2012 @ 12:28
    Ben Chambers
    0

    dynamicmedia umbraco file empty string

    i have a Razor macro that iterates through all child pages to display news items on a page. Each item has a media picker image which i want to display.

    i cannot obtain the url for the media as the umbracofile property returns an empty string. i have downloaded the patch mentioned here http://umbraco.codeplex.com/workitem/30778 but unfortunately as i am new to Umbraco i have no idea how to apply this or if in fact this will fix it.

    Any help would be greatly apprerciated.

    the code for my macro is below.

        @{
            @* -- Setup a counter variable for position -- *@
            var position = 1;
        }
        @* -- List children pages from the current page (aka Model) -- *@
        @foreach (var page in @Model.Children.Where("umbracoNaviHide != true"))
        {
           
            <div id="mainColumnNews">
                <h2>@page.MediaById(@page.newsImage).umbracoFile</h2>
                <img  src="@page.MediaById(@page.newsImage).umbracoFile" alt="@page.newsTitle" style="width:270px;border-width:0px;" />
                <span>
                    @* -- If the page is an EventItem then display the date from the property alias 'eventDate' if it is not empty -- *@
                    @if (page.NodeTypeAlias == "EventItem" && page.eventDate.ToString() != "")
                    {
                    <h2>
                        <span>@page.date.ToString("dd.MM.yyyy")</span> -
                        <span>@page.newsTitle </span>                 
                    </h2>
                    }
                    else
                    {
                    <h2>
                        <span>@page.CreateDate.ToString("dd.MM.yyyy")</span> -
                        <span>@page.newsTitle </span>                 
                    </h2>
                    }
                </span>
               
               
                @{
                    var bodyText         = @page.newsText.ToString();
                    var bodyTextNoHtml   = umbraco.library.StripHtml(bodyText);
                    var bodyTextTrunc    = umbraco.library.TruncateString(bodyTextNoHtml, 100, "...");
                }

                <p>
                    <span>
                    @bodyText
                </span>               
                </p>
            </div>
           
            @* -- After every 3rd item insert a <br/> -- *@
            if (position % 3 == 0)
            {
                <br class="clearBoth"/>
            }
           
            @* -- Increase the position counter by 1 -- *@
            position++;
        }

  • Douglas Ludlow 210 posts 366 karma points
    Apr 20, 2012 @ 19:15
    Douglas Ludlow
    0

    Try using @Library.MediaById(id) instead of @page.MediaById(id).

Please Sign in or register to post replies

Write your reply to:

Draft