I have a very simple gallery to create on page. Here are the bits I have put together for this task.
First I created a new media folder and in it put a few files. Each files is a jpg image.
For now each is called GalleryImage but I don't think that is the issue here.
I next created a Razor marco. Umbraco gave me a head start on this and for now i have left the razor code as Umbraco supplied bar some test values. Here it is.
@inherits umbraco.MacroEngines.DynamicNodeContext
@*
Macro Parameters To Create, for this macro to work:
Show:True Alias:mediaId Name:Media Folder ID Type:MediaCurrent
*@
@if (Parameter.mediaId != null)
{
@* Get the media folder as a dynamic node *@
var mediaFolder = Library.MediaById(Parameter.mediaId);
if (mediaFolder.Children.Any())
{
<ul>
@* for each item in children of the selected media folder *@
@foreach (var mediaItem in mediaFolder.Children)
{
<li><img src="@mediaItem.umbracoFile" alt="@mediaItem.Name" /></li>
}
</ul>
}else
{
<ul>
<li>test</li>
</ul>
}
<h3>here</h3>
}
. . . where 1117 is the id of the GalleryImages folder above.
When run the page NOTHING appears. No error, not markup, no images, nothing. It's like the macro is getting ignored. You can see why I added the else condition, and then in despiration I added the h3 title.
I was not creating the parameter in the Macro settings..
I'm not sure why this fixed it. I mean I had that parameter set in the template that is using the marco. Must be some behind the scenes Umbraco stuff going on here.
A simple gallery using Razor and Media
I have a very simple gallery to create on page. Here are the bits I have put together for this task.
First I created a new media folder and in it put a few files. Each files is a jpg image.
For now each is called GalleryImage but I don't think that is the issue here.
I next created a Razor marco. Umbraco gave me a head start on this and for now i have left the razor code as Umbraco supplied bar some test values. Here it is.
Finally, I placed the macro in the template.
. . . where 1117 is the id of the GalleryImages folder above.
When run the page NOTHING appears. No error, not markup, no images, nothing. It's like the macro is getting ignored. You can see why I added the else condition, and then in despiration I added the h3 title.
What am I missing here?
Hi Brad,
Try changing
var param = @Parameter.mediaId;
var mediaFolder = Model.MediaById(@param) ;
Thanks Fuji but no go.
As a test I changed my macro to this. .
I also noted the 'for this macro to work' text above. I'm not to sure what this all means.Here is my markup for the macro in the template.
Running this I get the text "This is some text", but mediaId has no vallue.
This is the problem.
Ok, I fixed this..
I was not creating the parameter in the Macro settings..
I'm not sure why this fixed it. I mean I had that parameter set in the template that is using the marco. Must be some behind the scenes Umbraco stuff going on here.
is working on a reply...