Skip to content
Jeavon edited this page Aug 24, 2016 · 6 revisions

Using without Umbraco Models Builder

Using in Razor (property alias "widgetLink") for a single mode picker

@using UrlPicker.Umbraco.Models
@if (Model.Content.HasValue("widgetLink"))
{
	var widgetLink = Model.Content.GetPropertyValue<UrlPicker>("widgetLink");
	var linkTarget = widgetLink.Meta.NewWindow ? "_blank" : null;
	var linkUrl = widgetLink.Url;
	var linkText = widgetLink.Meta.Title;

	if (widgetLink.Type == UrlPicker.UrlPickerTypes.Url)
	{
		if (!string.IsNullOrEmpty(linkUrl) && !(linkUrl.StartsWith("http://") && !(linkUrl.StartsWith("https://"))))
		{
			linkUrl = "http://" + linkUrl;
		}
	}

	if (!string.IsNullOrEmpty(linkUrl))
	{
		<a href="@linkUrl" target="@linkTarget">@linkText</a>
	}
}

Using in Razor (property alias "footerLinks") for a multiple mode picker

@if (Model.Content.HasValue("footerLinks"))
{
	foreach (var link in Model.Content.GetPropertyValue<IEnumerable<UrlPicker>>("footerLinks"))
	{
		var linkTarget = link.Meta.NewWindow ? "_blank" : null;
		var linkUrl = link.Url;
		var linkText = link.Meta.Title;

		if (link.Type == UrlPicker.UrlPickerTypes.Url)
		{
			if (!string.IsNullOrEmpty(linkUrl) && !(linkUrl.StartsWith("http://") && !(linkUrl.StartsWith("https://"))))
			{
				linkUrl = "http://" + linkUrl;
			}
		}

		if (!string.IsNullOrEmpty(linkUrl))
		{
			<a href="@linkUrl" target="@linkTarget">@linkText</a>
		}

	}
}

Using with Umbraco Models Builder

Using in Razor (property alias "widgetLink") for a single mode picker

@if (Model.Content.WidgetLink != null)
{
	var linkTarget = Model.Content.WidgetLink.Meta.NewWindow ? "_blank" : null;
	var linkUrl = Model.Content.WidgetLink.Url;

	if (Model.Content.WidgetLink.Type == UrlPicker.UrlPickerTypes.Url)
	{
		if (!string.IsNullOrEmpty(linkUrl) && !(linkUrl.StartsWith("http://") && !(linkUrl.StartsWith("https://"))))
		{
			linkUrl = "http://" + linkUrl;
		}
	}

	if (!string.IsNullOrEmpty(linkUrl))
	{
		<a href="@linkUrl" target="@linkTarget">@Model.Content.WidgetLink.Meta.Title</a>
	}
}

Using in Razor (property alias "footerLinks") for a multiple mode picker

@if (Model.Content.FooterLinks != null)
{
	foreach (var link in Model.Content.FooterLinks)
	{
		var linkTarget = link.Meta.NewWindow ? "_blank" : null;
		var linkUrl = link.Url;

		if (link.Type == UrlPicker.UrlPickerTypes.Url)
		{
			if (!string.IsNullOrEmpty(linkUrl) && !(linkUrl.StartsWith("http://") && !(linkUrl.StartsWith("https://"))))
			{
				linkUrl = "http://" + linkUrl;
			}
		}

		if (!string.IsNullOrEmpty(linkUrl))
		{
			<a href="@linkUrl" target="@linkTarget">@link.Meta.Title</a>
		}
	}
}