I am trying to learn Umbraco. I have subscribed to umbraco.tv and watched all of the videos, and I am trying to make my way through the documentation, but I am stuck.
I am trying to create a macro with 4 parameters (image, text, title, link). I am using the razor partial macro with the following code:
The Title and text display fine, but the image is not displaying. I can kind of understand what I am doing wrong with the Image parameter, but I can't work out how to get it to display. I would be grateful for any help!!
The id of the image is passed so you still need to do some lifting to render an image (this actually provides more flexibility,...).
@inherits Umbraco.Web.Macros.PartialViewMacroPage
<div>
<div class="col-md-6">
@{
// Umbraco passes us an ID to the image so we need to get it and render it
var image = Umbraco.TypedMedia(@Model.MacroParameters["Image"]);
if(image != null)
{
<img src="@image.Url" alt="@image.Name" class="img-class"/>
}
}
</div>
<div class="col-md-6">
<h1>@Model.MacroParameters["Title"]</h1>
<div>@Model.MacroParameters["Text"]</div>
</div>
</div>
Macro Media (Razor)
Hi,
I am trying to learn Umbraco. I have subscribed to umbraco.tv and watched all of the videos, and I am trying to make my way through the documentation, but I am stuck.
I am trying to create a macro with 4 parameters (image, text, title, link). I am using the razor partial macro with the following code:
The Title and text display fine, but the image is not displaying. I can kind of understand what I am doing wrong with the Image parameter, but I can't work out how to get it to display. I would be grateful for any help!!
Hi Jon-Paul,
Macro parameter stores id of Umbraco Media. So you need to get image by Id and render it.
Cheers
Hi,
The id of the image is passed so you still need to do some lifting to render an image (this actually provides more flexibility,...).
Hi,
UPDATE: Alex beat me to it!
Kind regards
Steve
Hi - Thanks both. You have saved me a great deal of time.
You are welcome.
is working on a reply...