Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Url to page - link collection style

Vote:
 

Hi

i wanted to build custom property to url that uses the Information + Link target  and not just the information ( i want it to behave like the link collection property ( it returns in code a linkitem with the information)

i tried to use the propertyurl control but it still render the information without the link traget

#37609
Mar 14, 2010 17:03
Vote:
 

This is exactly what I also wanted to do. But some of it are made internal.

Take a look at my rant about this :)

This is the code you need: And it makes a link aviable, and render it as a one link

  [Serializable]
    [PageDefinitionTypePlugIn()]
    public class PropertyOneLink : PropertyLinkCollection
    {
        public LinkItem MyLink
        {
            get
            {
                if (this.Links != null && this.Links.Count > 0)
                    return this.Links[0];
                return null;
            }

        }
        public override EPiServer.Core.IPropertyControl CreatePropertyControl()
        {
            return new PropertyOneLinkControl();
        }
    }
    public class PropertyOneLinkControl : PropertyDataControl, INamingContainer
    {

        // Fields
        private Control editControl;

        // Methods
        public override void ApplyEditChanges()
        {
            try
            {
                this.PropertyLinkCollection.Links = ((IPropertyLinkCollectionEditControl)this.editControl).NewLinkCollection;
            }
            catch (Exception exception)
            {
                this.AddErrorValidator(exception.Message);
            }
        }

        public override void CreateDefaultControls()
        {
            base.CopyWebAttributes(this);

            foreach (LinkItem item in this.PropertyLinkCollection)
            {

                Literal literal = new Literal();
                literal.Text = item.ToMappedLink();
                this.Controls.Add(literal);

            }
        }
        Repeater repeater;
        public override void CreateEditControls()
        {
            this.editControl = this.Page.LoadControl(UriSupport.ResolveUrlFromUIBySettings("Edit/PropertyLinkCollectionEditControl.ascx"));

            ((IPropertyLinkCollectionEditControl)this.editControl).OriginalLinkCollection = this.PropertyLinkCollection.Links;
            this.Controls.Add(this.editControl);
            ((IPropertyLinkCollectionEditControl)this.editControl).OriginalLinkCollection = this.PropertyLinkCollection.Links;
            repeater = editControl.FindControl("Links") as Repeater;
            editControl.PreRender += new EventHandler(editControl_PreRender);
        }

 

        void editControl_PreRender(object sender, EventArgs e)
        {
            var a = ((IPropertyLinkCollectionEditControl)editControl).NewLinkCollection;
            if (repeater.Controls.Count > 0)
            {
                Control header = repeater.Controls[0];

                header.Controls.Clear();
                Literal l = new Literal();
                l.Text = "<table  class=\"epistandardtable\" style=\"width:200px;\">";
                header.Controls.Add(l);
            }
            repeater.Visible = (a.Count > 0);
            editControl.FindControl("AddLinkButton").Visible = !(a.Count > 0);
        }

 

        // Properties
        private PropertyLinkCollection PropertyLinkCollection
        {
            get
            {
                return (base.PropertyData as PropertyOneLink);
            }
        }
    }

#37616
Edited, Mar 15, 2010 9:25
Vote:
 

YES !!!

sweet exactly what i needed

strange that epi didn't add out of the box supprt for links with target and title , every new site need it for SEO and etc.

#37624
Mar 15, 2010 12:37
Vote:
 

I total agree with you. You could post a comment on the blog to raise you opinion.. http://bit.ly/9yCBMe

#37626
Edited, Mar 15, 2010 12:42
Vote:
 

Am i correct, that after 5 years, this BASIC functionality (setting the target for a single link) is still not tackled in Episerver 9???? The last couple of weeks i have so many responses to my questions (which luckily did solve most of them!) which required me to 'hack' or in elegant terms 'write an extension or override' functionality that should be there from the start...

More and more i get the feeling that Episerver CMS is more of a basic CMS framework, instead of a fully functioning Content Management System.... :-(

Please i'm open for suggestion, so i hope you guys can prove me wrong.

#140553
Oct 22, 2015 16:03
Vote:
 

Ron, I don't know what you're talking about. You have been able to set target on links as long as I can remember... If you want to extend the regular Url property, just create a block with the properties you need then a view for it.

#140571
Oct 22, 2015 18:46
Vote:
 

And here's some code for you...

The link block:

[ContentType(
    GUID = "379e3ef7-6854-4cef-acbf-4eef3490db27",
    AvailableInEditMode = false)]
public class LinkWithTextBlock : BlockData
{
    [CultureSpecific]
    [Display]
    public virtual string LinkText { get; set; }

    [CultureSpecific]
    [DefaultDragAndDropTarget]
    [Display]
    public virtual Url LinkUrl { get; set; }
}

Then in your page type:

[ContentType(GUID = "a04d5be6-bd62-4333-9645-058ed0c91246")]
public class RegularPage : PageData
{
    [Display]
    public virtual LinkWithTextBlock Link { get; set; }
}

Your view for RegularPage

@Html.PropertyFor(m => m.CurrentPage.Link)

Then you have to create a partial view for LinkWithTextBlock.

#140572
Oct 22, 2015 18:52
Vote:
 

And just to be clear; there is no Link property in EPiServer. But you have Url, which obviously only stores an URL. So if you want to store more information, like a link, just create a block.

#140573
Oct 22, 2015 18:58
Vote:
 

This is my popup window for an url property for Episerver 9. As you can see there is no target option

http://postimg.org/image/9os6t9xoj/

#140625
Edited, Oct 26, 2015 10:44
Vote:
 

As I wrote, it's an URL, not a link. If you need a link property you have to either develop a new property type yourself or use a local block (block as property).

#140626
Oct 26, 2015 10:47
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.