I have a XML Dropdown Picker, where the editor can pick a region.
When a item is picked I can display a Custom Label, e.g. the node id + node name and make it as a link to the picked node.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
IPublishedContent content = Umbraco.TypedContent(Model.MacroParameters["key"]);
if (content != null)
{ string link = "/umbraco/#/content/content/edit/" + content.Id;
<a href="@link">@content.Id: @content.Name</a>
}
else
{
@Html.Raw("<span>No region selected.</span>")
}
}
But for "Region 2" (which is not picked) it doesn't seem to render the macro or reach the else block.
Furthermore if I change the dropdown back to the initial value (blank value) it still display the relation on "Region 1" even the relation shouldn't be active anymore and the macro cache is disabled.
nuPickers.RelationLabels only render the script Custom Label through the macro, when there is a relation to the selected node. So at the moment in the current version it doesn't seem to be possible to render a "empty/blank/fallback" label.
Display Custom Label when no item is selected
I have a XML Dropdown Picker, where the editor can pick a region.
When a item is picked I can display a Custom Label, e.g. the node id + node name and make it as a link to the picked node.
But for "Region 2" (which is not picked) it doesn't seem to render the macro or reach the else block.
Furthermore if I change the dropdown back to the initial value (blank value) it still display the relation on "Region 1" even the relation shouldn't be active anymore and the macro cache is disabled.
/Bjarne
Hi Bjarne
What if you check the Model.MacroParameters["key"] for an empty or null value instead of calling the TypedContent helper?
Maybe the helper is returning something which makes the if always true? I cant remember the default behaviour without looking it up.
Damian
Just tested and typedcontent does seem to return null when it cant find a node... What value is in Model.MacroParameters["key"] when it is empty ?
Are you getting an error and nothing displayed because the error is caught further up the stack?
Just throwing a few ideas around for you.
Damian
Hi Damian
I tried also to check if the macroparameter has a value... problem is that the macro only seems to render, when there is a relation.
This is only printed when the node is selected, otherwise it doesn't seem to render the macro.
/Bjarne
nuPickers.RelationLabels only render the script Custom Label through the macro, when there is a relation to the selected node. So at the moment in the current version it doesn't seem to be possible to render a "empty/blank/fallback" label.
is working on a reply...