but not having any joy with it, I have tried every possible BaseElement value, removing the dashes etc, but I never get any items return from the list.
Thing is I am puzzled as to how Ismail's code could work, although maybe the uComponenets team have refactored the node names since his post.
I use this (using 4.7.1: I just copied the umbraco.MacroEngines.dll from latest nightly build of umbraco 4.7.1. http://nightly.umbraco.org/umbraco%204.7/4.7%20RC/), Considering that the property alias for the multi url picker in my case is "urlPicker":
foreach (var link in Model.UrlPicker.urlpicker) { <a href="@link.url" @Html.Raw(link.newwindow == "True" ? "target=\"_blank\"" : "")>@link.linktitle</a><br /> }
Thanks Sebastiaan - I hereby declare you my Person of the Week! Lovely clean solution, that one has been bugging me for ages. To clarify for other readers, based on the data above my code is as follows (where multi url picker alias is 'relatedLinks')
foreach (var link in Model.relatedLinks.urlpicker) { <a href="@link.url"@Html.Raw(link.newwindow =="True"?"target=\"_blank\"":"")>@link.linktitle</a><br /> }
This issue was fixed in 4.7.1, but still has a bug in 4.7.1.1: http://umbraco.codeplex.com/workitem/30680. It will be fixed in the next release or you can already copy over the latest umbraco.MacroEngines.dll from the nightlies.
var topNavLinks = @Model._topNavigationLinks;
if (!string.IsNullOrEmpty(topNavLinks))
{
foreach (var link in Model.topNavigationLinks.urlpicker)
{
<li><a href="@link.url"@Html.Raw(link.newwindow == "True" ? "target=\"_blank\"" : "")>@link.linktitle</a></li>
}
}
This is untested but should give you an idea. Note the underscore before the property name to make it walk up the tree recursively. I believe this convention exists since v4.7.1.
I also have a node with a property which uses a datatype of type uComponents Multi-Url Picker. I'm able to get the values from the Multi-Url Picker from the current page or model using the code below, however I am unable to make it recursive. Can anyone suggest a way of doing this?
(I am using Umbraco version 4.11.1)
@inherits umbraco.MacroEngines.DynamicNodeContext @using umbraco.MacroEngines; @using uComponents.DataTypes.MultiUrlPicker.Dto; @{ if (Model.HasValue("selectPods")) { var podSelection = Model.GetProperty("selectPods", true).Value; MultiUrlPickerState pods = @GlobalHelpers.GetMultiUrlPickerState(podSelection);
if (pods.Items.Any()) { foreach (var item in pods.Items) { var itemId = item.NodeId.ToString(); var itemNode = Library.NodeById(itemId); if (!String.IsNullOrEmpty(itemId)) { var pageNode = Model.NodeById(itemId); if (pageNode.HasValue("podContent")) { var pageLink = pageNode.NiceUrl; var pageTitle = pageNode.GetProperty("pageTitle").Value; var podTitle = (!String.IsNullOrEmpty(pageTitle)) ? pageTitle : pageNode.Name; var itemIntro = pageNode.GetProperty("podContent").Value; string itemImage = pageNode.GetProperty("podImage").Value;
var podImageThumb = Library.ToDynamicXml(itemImage); foreach (var podItem in podImageThumb) { var image = podItem.Image;
I'm showing a list of Multi-URL Picker links in a partial view in Umbraco 6 MVC, and the Model.relatedResources.urlpicker syntax doesn't work because the model of the partial view is IPublishedContent.
Currently I'm using this helper to show the links, but I wonder if there is a better solution:
@* Show a list of links based on the value of a uComponents Multi-URL Picker.
include using uComponents.DataTypes.MultiUrlPicker.Dto *@
Razor script to iterate through uComponents multi URL picker nodes
Can anyone lend a hand getting me started with a razor script to loop through a multi URL? The XML data of my node is as follows:
<multi-url-picker>
<url-picker mode="URL">
<new-window>False</new-window>
<node-id />
<url>www.google.com</url>
<link-title />
</url-picker>
<url-picker mode="Content">
<new-window>False</new-window>
<node-id>1094</node-id>
<url>/about-us/</url>
<link-title />
</url-picker>
</multi-url-picker>
Based on another post from Ismail I got to this point:
var relatedLinksNode = Model.relatedLinks;
foreach (XElement item in relatedLinksNode.BaseElement.Elements("url-picker"))
{
if (item.Attribute("mode").Value == "url")
{
<li><a href="@umbraco.library.NiceUrl(int.Parse(item.Attribute("url").Value))">[title]</a></li>
}
else
{
<li><a href="@item.Attribute("url").Value" rel="external">[title]</a></li>
}
}
but not having any joy with it, I have tried every possible BaseElement value, removing the dashes etc, but I never get any items return from the list.
Thing is I am puzzled as to how Ismail's code could work, although maybe the uComponenets team have refactored the node names since his post.
I use this (using 4.7.1: I just copied the umbraco.MacroEngines.dll from latest nightly build of umbraco 4.7.1. http://nightly.umbraco.org/umbraco%204.7/4.7%20RC/), Considering that the property alias for the multi url picker in my case is "urlPicker":
Thanks Sebastiaan - I hereby declare you my Person of the Week! Lovely clean solution, that one has been bugging me for ages. To clarify for other readers, based on the data above my code is as follows (where multi url picker alias is 'relatedLinks')
Hi there
I'm trying to create a generic Razor script where you select the Multi URL picker field in the macro (using a propertyTypePicker).
So, ideally, I'd like to do something like this:
But this doesn't work.
Any ideas?
Mike
I found this while looking for help with getting the values from the Mult URL picker and I got it to work.
My question is ( it might be a noob razor question) is why if the xml node name is link-title? why do you refrer to it as linktitle in razor.
When I had link-title, I would be back no node with link
Because the name of the xml node needs to be translated to a C# method name and method names cannot have a regular dash in them.
This issue was fixed in 4.7.1, but still has a bug in 4.7.1.1: http://umbraco.codeplex.com/workitem/30680. It will be fixed in the next release or you can already copy over the latest umbraco.MacroEngines.dll from the nightlies.
Jeroen
Is it possible to check if the urlpicker has any items?
Model.relatedLinks.urlpicker.Count() causes an error if the user hasn't picked any.
Hi,
I have a node with a property which uses a datatype of type: Multi-Url Picker.
I can get the values using the code below, but how do i make it recursive?
I want to show the same links on child nodes.
You could try something like this:
This is untested but should give you an idea. Note the underscore before the property name to make it walk up the tree recursively. I believe this convention exists since v4.7.1.
Sorry slight mistake in the above but this crappy forum editor won't let me edit it! See the amended version below:
Hi,
I ended up doing it like this:
@inherits umbraco.MacroEngines.
DynamicNodeContext
@
using umbraco.MacroEngines;
@
using uComponents.Core.DataTypes.MultiUrlPicker.Dto;
@{
MultiUrlPickerState selectedLinks = GlobalHelpers.GetMultiUrlPickerState(Model.GetProperty("topNavigationLinks", true).Value);
if (selectedLinks.Items.Any())
{
foreach (var link in selectedLinks.Items)
{
var target = link.NewWindow ? "target=\"_blank\"" : "";
<li><ahref="@link.Url"@target>@link.Title</a></li>
}
}
//<multi-url-picker><url-picker mode="URL"><new-window>False</new-window><node-id /><url>http://www.domain1.com</url><link-title>Name1</link-title></url-picker><url-picker mode="URL"><new-window>False</new-window><node-id /><url>domain2</url><link-title>name2</link-title></url-picker></multi-url-picker>
}
Hi,
I also have a node with a property which uses a datatype of type uComponents Multi-Url Picker. I'm able to get the values from the Multi-Url Picker from the current page or model using the code below, however I am unable to make it recursive. Can anyone suggest a way of doing this?
(I am using Umbraco version 4.11.1)
Hi,
When I try to loop through the uComponent Multi-URL Picker links like this:
foreach (var link in Model.uBlogsyPostLinks.urlpicker) {
....
}
I get the following error on 'Model.uBlogsyPostLinks':
'uComponents.DataTypes.MultiUrlPicker.Dto.MultiUrlPickerState' does not contain a definition for 'urlpicker'
Is there something I'm missing here?
My Umbraco version is 4.11.3.1 and my version of uComponents is 3.5
Thanks for your help,
Anthony
Hi,
I using Umbraco v4.11.3.1 and uComponents v3.5
When I try to loop through the related links like this:
foreach(var link in Model.uBlogsyPostLinks.urlpicker)
{
....
}
I get the following runtime error: 'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'urlpicker'
Has there been something changed, so that the solution by Sebastiaan doesn't work anymore?
Thanks for your help,
Anthony
Anyone has a clue what's going on here:
the code:
foreach (var link in Model.UrlPicker.urlpicker)
....
result in the following runtime error:
'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'urlpicker'
I'm using Umbraco v.4.11.3.1 and uComponents v3.5
Thanks for your help,
Anthony
Anthony, did you get anywere with this? i am bumping into exact same issue.
I've been happily using the code from the razor macro package by Sebastiaan Janssen and the code I have working is based on
thanks Ravi!
I'm showing a list of Multi-URL Picker links in a partial view in Umbraco 6 MVC, and the Model.relatedResources.urlpicker syntax doesn't work because the model of the partial view is IPublishedContent.
Currently I'm using this helper to show the links, but I wonder if there is a better solution:
Hi John,
I tried your method to do that, but MultiUrlPickerState.Deserialize method returns empty collection always ((
I don't know what to do.
Any suggestions ?
THanks,
Alex
Hi Alex,
What does the content of your "linklist" string look like? E.g. mine is:
My is :
It looks like you are using a different datatype for your field. Mine is: "uComponents: Multi-URL Picker".
Could it be that yours is: "Multi-Node Tree Picker" ? (I'm referring to the value of the Property editor field in the configuration of the datatype.)
My is "Related Links" )) so it's the problem I see.
Thanks
Hi guys
For what it's worth, this seems to work for me:
@foreach (var link in Model.myLinks.Items)
{
<li><a href="@link.Url">Link</a></li>
}
Ben
is working on a reply...