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++; }
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++;
}
Try using @Library.MediaById(id) instead of @page.MediaById(id).
is working on a reply...