Opticon Stockholm is on Tuesday September 10th, hope to see you there!
Opticon Stockholm is on Tuesday September 10th, hope to see you there!
Im looking for something like this: https://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/partial-tag-helper?view=aspnetcore-6.0#view-data
but when testing <div epi-property="@Model.CurrentPage.ImageAsContentReference" view-data='@(new ViewDataDictionary(ViewData) { { "width", 300 },{ "height", 300},{ "format", "webp" } })' />
it is rendering
<div view-data="Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary"> ... content comes here ... </div>
We wanted the block to know their context, so we ended up using TempData in the MVC Views...
TempData["whereAmI"] = "left";
Html.PropertyFor(m => m.CurrentContent.LeftContentArea)
and then in the block view:
string whereAmI = TempData["whereAmI"] != null ? TempData["whereAmI"].ToString() : string.Empty;
With tag helpers you dont necessarily need to even use additional properties like this. For instance, in your example:
@Html.PropertyFor(m => Model.CurrentPage.ImageAsContentReference, new { width = 300, height = 300, format = "webp"});
At least for the width and height, you can just add them to the tag:
<div epi-property="@Model.CurrentPage.ImageAsContentReference" width="300" height="300" />
Im a little less clear on the format property, so in that case, that might not work. What does that tag do? You could conceivably make a custom taghelper just to handle the 'format' piece. So, your taghelper would target a div and render certain attributes depending on the value. So, two tag helpers on the same tag. Im fairly certain that would work.
CMS12
Is there a way to send viewdata parameters with use of taghelper epi-property?
<div epi-property="@Model.CurrentPage.ImageAsContentReference" />
The equivalence with HtmlHelpers:
@Html.PropertyFor(m => Model.CurrentPage.ImageAsContentReference, new { width = 300, height = 300, format = "webp"});
then i can further down in the stack get the data with "ViewData" in my displaytemplate