November Happy Hour will be moved to Thursday December 5th.

URL Property for creating Target

Vote:
 

I need to set the Target from the URL property. Please find the below My code snippet

 

  [Editable(true)]
        [Display(
            Name = "Twitter URL",
            Description = "Twitter URL property",
            GroupName = TabNames.Footer,
            Order = 400)]
        public virtual Url TwitterURL { get; set; }

 

In the above code I need to get and assign the "Ahref" Target value.

I have also used "LinkItemCollection" for getting more LinkItems. So that I can get the Target value, like below.

 string aHref = @Html.GetFriendlyURL(null, @Footernav2.Href);
 <a href="@aHref" target="@Footernav2.Target">@Footernav2.Text</a>

The same way, I need to get the Target value for the single Link Item. Kindly help to achive this.

 

 

#72423
Jun 17, 2013 12:00
Vote:
 

There is no way to determine a target for a single link item when you only have a property of type Url.

When you have a LinkItemCollection, you have a list of "LinkItem". A LinkItem have the attribute selected by the editor stored to Target.
For example

@foreach(LinkItem item in CurrentPage.MyLinkItemCollection)
{ <a href="@Html.GetFriendlyURL(item.Href)" @(!String.IsNullOrEmpty(item.Target) ? "target=\"" + @item.Target + "\"" : "")>@item.Text</a> }

    

Given that you have an Extension method on HtmlHelper called GetFriendlyURL. Note that Target is usually empty, hence you need to check the value before rendering the target-attribute or you will render target="".

If you want to render a complete link including the href, target and text without any custom html or attributes, you could use @Html.PageLink(item)

#72431
Edited, Jun 17, 2013 13:49
Vote:
 

Thanks for your reply, Yes URL alone we can't do anything and also Epi not allows LinkItem as a separate property type.

So, is there any possible way to control the number of link item to  Linkitemcollection property ?

For example; at this scenario, the end-user needs to add only one item into the LInkitemcollection proerty.

#72432
Jun 17, 2013 14:05
Vote:
 

You can build a validator attribute of your own, you can find some inspiration on http://world.episerver.com/Blogs/Alexander-Haneng/Dates/2013/1/Limiting-a-Page-Property-to-a-specific-Page-Type-in-EPiServer-7/

Personaly I think I would create a Block that contains a Url, Target and Text instead of the entire functionality you will get from the LinkItemCollection.

#72433
Jun 17, 2013 14:10
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.