Probaply a total newbie question here, but I am trying to create a list of links that I can re-use on different pages. I wanna create a list of active campaigns. I have created a uComponents MultiUrlPicker, and saved it in a container on my root.
On my page I have a content picker which points to the MultiUrlPicker. How do i do a foreach loop that shows all the links in the multiurlpicker?
Here is what I have so far - but I don't think I am even close to the solution.
var kampagneLink = Model.Content.GetPropertyValue("kampangeLinks"); //Returns id of container
<ul>
@if (kampagneLinks != null) {
foreach (var link in Model.Content.GetPropertyValue<MultiUrlPickerState>("kampagneLinks").items)
{
if (!link.Validates())
{
continue;
}
<li><a href="@link.Url" target="@(link.NewWindow ? "_blank" : "_self")">@link.Title</a></li>
}}</ul>
I hope someone can guide me in the right direction.
I think what you were missing is that Model.Content is the current page. After you grab the kampagneLinkContainer (shown in the first couple of lines below) you need to get the MultiUrlPickerState data off of the kampagneLinkContainer node instead of off of the current page.
var kampagneLinkId = Model.Content.GetPropertyValue("kampangeLinks"); //Returns id of container
var kampagneLinkContainer = Umbraco.TypedContent(kampagneLinkId);
<ul>
@if (kampagneLinkContainer != null) {
foreach (var link in kampagneLinkContainer.GetPropertyValue<MultiUrlPickerState>("kampagneLinks").items)
{
if (!link.Validates())
{
continue;
}
<li><a href="@link.Url" target="@(link.NewWindow ? "_blank" : "_self")">@link.Title</a></li>
}
}
</ul>
Thank you for your quick reply :-) Unfortunately it is not working. It tells me that
CS1061: 'uComponents.DataTypes.MultiUrlPicker.Dto.MultiUrlPickerState' does not contain a definition for 'items'
Is it not possible to simply use the first variable (kampagneLinkId) in the foreach sentence? This variable returns the id of the muliturlpicker - shouldn't I be able to do something like this:
foreach (var link in 8888.items)
where 8888 beeing the ID of the multiUrlPicker in content
Calling a multiurlpicker from a contentpicker
Hi folks,
Probaply a total newbie question here, but I am trying to create a list of links that I can re-use on different pages. I wanna create a list of active campaigns. I have created a uComponents MultiUrlPicker, and saved it in a container on my root.
On my page I have a content picker which points to the MultiUrlPicker. How do i do a foreach loop that shows all the links in the multiurlpicker?
Here is what I have so far - but I don't think I am even close to the solution.
I hope someone can guide me in the right direction.
Best regards Jimmy Dan Mortensen
I think what you were missing is that
Model.Content
is the current page. After you grab thekampagneLinkContainer
(shown in the first couple of lines below) you need to get the MultiUrlPickerState data off of thekampagneLinkContainer
node instead of off of the current page.Let me know how that works.
Hi Mark,
Thank you for your quick reply :-) Unfortunately it is not working. It tells me that
Is it not possible to simply use the first variable (kampagneLinkId) in the foreach sentence? This variable returns the id of the muliturlpicker - shouldn't I be able to do something like this:
where 8888 beeing the ID of the multiUrlPicker in content
is working on a reply...