Trouble accessing media picker image within document type in template
I have created a document type with no template named "Application" and have added an Image Media Picker to it with an alias of "logo" and a textstring with an alias of "description".
I have created a couple instances of that document type and have attached them to another document type named "Home" as children.
In Home's template I am attempting to show the selected images by doing the following:
I have tried this adding the generic type specifier by doing @block.Value. When I do that my template fails to load and I get the following exception on my logs.
Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto.UmbracoCompilationException: Exception of type 'Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto.UmbracoCompilationException' was thrown.
at Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto.CollectibleRuntimeViewCompiler.CompileAndEmit(String relativePath)
at Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto.CollectibleRuntimeViewCompiler.OnCacheMiss(String normalizedPath)
If I try do access a property I also get an error:
@block.Value("Logo").Content
yields this in the logs:
error CS1061: 'object' does not contain a definition for 'Content' and no accessible extension method 'Content' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Does anyone have any suggestions about what is going wrong? I did not think it would be this tough to get the image out of the media picker.
Trouble accessing media picker image within document type in template
I have created a document type with no template named "Application" and have added an Image Media Picker to it with an alias of "logo" and a textstring with an alias of "description".
I have created a couple instances of that document type and have attached them to another document type named "Home" as children.
In Home's template I am attempting to show the selected images by doing the following:
The descriptions come through just fine.
The logo outputs:
Umbraco.Cms.Core.Models.MediaWithCrops`1[Umbraco.Cms.Web.Common.PublishedModels.Image]
I am trying to access the media image so I can display it on the page.
I searched online and saw suggestions like:
I have tried this adding the generic type specifier by doing @block.Value. When I do that my template fails to load and I get the following exception on my logs.
Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto.UmbracoCompilationException: Exception of type 'Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto.UmbracoCompilationException' was thrown. at Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto.CollectibleRuntimeViewCompiler.CompileAndEmit(String relativePath) at Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto.CollectibleRuntimeViewCompiler.OnCacheMiss(String normalizedPath)
If I try do access a property I also get an error:
yields this in the logs:
error CS1061: 'object' does not contain a definition for 'Content' and no accessible extension method 'Content' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Does anyone have any suggestions about what is going wrong? I did not think it would be this tough to get the image out of the media picker.
Here are the associate docs: https://docs.umbraco.com/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/media-picker-3
Hi Jessie,
try using the below
@block.Value<MediaWithCrops>("logo").Url()
and this needs to be used in the src attribute of an img tag to display the imageI continued to receive an error when trying to specify MediaWithCrops as the generic.
Here is what I had to do to get the logo to render:
is working on a reply...