Hi There, I'm looping through a list of child pages and passing the page id into a partial. From the partial i'd like to loop through all of the media items (in this case pdf files) that are attached to that particular page. How can I do this in razor?
Thanks in advance.
foreach (var pageCodeSnippets in Model.Content.Children())
I think that you can get the images from the are attached to that particular page, by doing something like this. From you code that you have posted in your post I assume that you´re using strongly typed razor.
@{ foreach (var pageCodeSnippets in Model.Content.Children()){
Thanks for the Answer much appreciated. I ended up with the following which seems to work locally anyway. Now I have to find out why it does not work on windows Azure.
Retrieve media items for current id
Hi There, I'm looping through a list of child pages and passing the page id into a partial. From the partial i'd like to loop through all of the media items (in this case pdf files) that are attached to that particular page. How can I do this in razor?
Thanks in advance.
foreach (var pageCodeSnippets in Model.Content.Children())
{
count++;
<h3>@pageCodeSnippets.GetProperty("snippetTitle").Value</h3>
<p>@pageCodeSnippets.GetProperty("snippetParagraph").Value</p>
<section class="section row">
<div id="snippet-@count">@Html.Raw(pageCodeSnippets.GetProperty("snippetbody").Value)</div>
</section>
@RenderPage("~/Views/Partials/_PDFThumbnailsView.cshtml", @pageCodeSnippets.Id)
}
!-- partial
var mediaFolder = "<Not Sure How To Do This>"
if (mediaFolder.Children.Any())
{
<ul>
@* for each item in children of the selected media folder *@
@foreach (var mediaItem in mediaFolder.Children)
{
int mediaID = mediaItem.Id;
var pdf = PDFHelper.GetMedia(mediaID);
<li>
<h5><a href="@mediaItem.umbracoFile">@mediaItem.Name</a></h5>
@*@foreach (var thumb in pdf.PdfThumbs)
{
<a target="_blank" href="@pdf.Media.Url"><img height="200" src="@thumb.fileName" [email protected]""></a>
}*@
</li>
}
</ul>
}
} else {
<p>is null</p>
}
Hi Sean,
I think that you can get the images from the are attached to that particular page, by doing something like this. From you code that you have posted in your post I assume that you´re using strongly typed razor.
Remember to change propertyAlias so it fetch your alias of your property where the user should choose the folder with the images.
Possibly take a look here: http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/54157-Rendering-Macro-inside-Partial-View
Hope this helps, or can be a good starting point at least,
/Dennis
HI Dennis,
Thanks for the Answer much appreciated. I ended up with the following which seems to work locally anyway. Now I have to find out why it does not work on windows Azure.
@* Check the document type *@
@if (Model.Content.DocumentTypeAlias == "CodeContentDocumentType")
{
int count = 0;
@* Get a list of properties from the current node *@
foreach (var pageCodeSnippets in Model.Content.Children())
{
count++;
<h3>@pageCodeSnippets.GetProperty("snippetTitle").Valueh3>
@* check that the article has files to go with it*@
if (pageCodeSnippets.HasValue("articleFiles"))
{
foreach (var mediaItem in @pageCodeSnippets.GetProperty("articleFiles").Value.ToString().Split(','))
{
int mediaID = int.Parse(mediaItem);
var pdf = PDFHelper.GetMedia(mediaID);
var mediaFiles = ApplicationContext.Current.Services.MediaService.GetById(mediaID);
var theCurrentFileName = String.Empty;
var theLastFileName = String.Empty;
@* loop through the list of thumbs only showing the first one*@
foreach (var thumb in pdf.PdfThumbs)
{
if (!String.IsNullOrEmpty(thumb.fileName))
{
theCurrentFileName = mediaFiles.Name;
if (theCurrentFileName != theLastFileName)
{
<div class="row">
<div class="pull-left">
<figure>
<a target="_blank" href="@pdf.Media.Url" title="@thumb.fileName"><img height="150" width="150" src="@thumb.fileName"alt="@mediaFiles.Name">a>
figure>
<div>
<a target="_blank" href="@pdf.Media.Url" title="Download @mediaFiles.Name" class="btn center-block">Downloada>
div>
div>
<div class="col-sm-9 pull-left">
<p class="text-muted">@mediaFiles.Namep>
<p>@pageCodeSnippets.GetProperty("snippetParagraph").Valuep>
div>
div>
}
theLastFileName = theCurrentFileName;
}
}
}
}
else
{
<p>You'll need to add an a file to see the rest of the article textp>
}
}
}
is working on a reply...