set the link property in episervear

Vote:
 

Hi have a page property and and pagelinkTitle property . I want to create a link like

<li><a href="#"><EPiServer:Property PropertyName="pagelinkTitle" runat="server" /></a></li>.

in my a href I want page Propert link. How do i write this property.

#46346
Dec 08, 2010 7:51
Vote:
 

There are many ways to do things like this, it depends on what you're after and in which context you are using it.

You can use the LinkURL property of the PageData object, like so <%= CurrentPage.LinkURL %>

If you are using this in a PageList for example you can use the Container.CurrentPage for the page currently in the loop of the pagelist. And you'd have to use DataBinding syntax <%# Container.Currentpage.LinkURL %>

You should also think about encoding the attribute, and possibly about getting a friendly url. You could also use a asp:HyperLink control and set things from codebehind and you wouldn't have to care about encoding.

The easiest way is really to use the property control with the PageLink property, which will render a link with the page's name as text: <EPiServer:Property PropertyName="PageLink" runat="server" />

#46350
Dec 08, 2010 9:27
Vote:
 

Hi Magnus!

Thanks for the Reply.

I am getting the value in the code behind like this way.

langLink.NavigateUrl = startPage["LanguageLink1"].ToString();

does the page type Property returns only pageid I want the pageLink but startPage["LanguageLink1"] gives me only the pageID.

#46351
Dec 08, 2010 10:28
Vote:
 

If your property "LanguageLink1" is of the type "Page" then it will contain a reference to the page, and if you ToString it, it will return the ID.

To get the URL you first need to get the PageData object corresponding to the reference, and to get that you first have to get the reference in it's right form:

var pageLink = startPage["LanguageLink1"] as PageReference;
var page = DataFactory.Instance.GetPage(pageLink);
var url = page.LinkURL

You should of course add some error handling for when the property is not set etc.

Edit: Typo

#46352
Edited, Dec 08, 2010 10:31
Vote:
 

Hi,

I am getting error in that

PageData startPage = DataFactory.Instance.GetPage(PageReference.StartPage);

var pageLink = startPage["LanguageLink1]" as PageReference;
var page = DataFactory.Instance.GetPage(pageLink);
var url = page.LinkURL

Cannot convert type string into episerver.core.pagerefrence.

#46353
Dec 08, 2010 10:38
Vote:
 

No that shouldn't even compile. I made a typo but corrected it. Intellisense should even tell you that there's something seriously wrong with that line :)

#46354
Dec 08, 2010 10:40
Vote:
 

You could also take a look at Itera:MultiProperty here you could render the code as this:

<Itera:Property runat="server" PropertyName="LanguageLink1">

<ItemTemplate><a href="{LanguageLink1.LinkURL}">{PageName}</a>

</Itera:Property>

This code will take the link from the page LanguageLink1 and the name of the currentpage.

#46369
Dec 08, 2010 14:25
Vote:
 

Hello,

 

I am trying to show the "domainName.com/" + the Simple address for the page or friendly URL.  Any ideas on how this could be possible for a pageTree?

#62530
Oct 29, 2012 0:17
Vote:
 
// Simple adress
UriBuilder url = new UriBuilder(Settings.Instance.SiteUrl);
url.Path = CurrentPage["PageExternalURL"] as string;

string simpleAdress = url.Uri.AbsoluteUri;

  And here's a handy extension method for friendly URL:

public static string ExternalURL(this PageData p, bool absoluteUrl)
{
    UrlBuilder pageURLBuilder = new UrlBuilder(p.LinkURL);

    Global.UrlRewriteProvider.ConvertToExternal(pageURLBuilder, p.PageLink, UTF8Encoding.UTF8);

    string pageURL = pageURLBuilder.ToString();

    if (absoluteUrl)
    {
        UriBuilder uriBuilder = new UriBuilder(Settings.Instance.SiteUrl);

        uriBuilder.Path = pageURL;

        return uriBuilder.Uri.AbsoluteUri;
    }

    return pageURL;
}

    

#62532
Edited, Oct 29, 2012 1:18
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.