How to remove item in Breadcrumb, something to do with langauges?

Vote:
 

How do I either remove the /en part of my site, or set a homepage for this language? Or better still, remove it from my code so it ignores this bit?

Getting "Missing text /navigation/startpage for en]" / Actual Homepage appear using the default episerver breadcrumb. Code as follows.

namespace EPiServer.Templates.Public.Units.Static

{

    /// <summary>

    /// Provide links back to each previous page that the user navigated through in order

    /// to get to the current page. In the case of the trail being too long, only the start page

    /// parent pages below the <see cref="MaxLength"/> threshold are shown.

    /// </summary>

    public partial class BreadCrumbs : UserControlBase

    {

        private const string _link = "<a href=\"{0}\" title=\"{1}\">{2}</a>";

        private string _separator = " / ";

        private int _maxLength = 60;

        /// <summary>

        /// In case the breadcrumb string is longer then the specified MaxLength,

        /// a shorter alternative is used where only the start page, parent page

        /// and the current page are shown.

        /// </summary>

        protected override void OnLoad(System.EventArgs e)

        {

            base.OnLoad(e);

            Breadcrumbs.Text = GenerateBreabCrumbs(CurrentPage);

        }

        /// <summary>

        /// Creates the bread crumb link string from the start page of the site to the supplied page

        /// </summary>

        /// <param name="page">The last page in the bread crumb string.</param>

        /// <returns>A bread crumb string with anchors to parent pages.</returns>

        private string GenerateBreabCrumbs(PageData page)

        {

            // Initiate a string builder based on max length. The generated html is considerably longer than the visible text.

            StringBuilder breadCrumbsText = new StringBuilder(8 * MaxLength);

            // Initiate a counter holding the visible length of the bread crumbs with the length of the start page link text.

            int breadCrumbsLength = Translate("/navigation/startpage").Length;

            while (page != null && page.PageLink != PageReference.StartPage)

            {

                breadCrumbsLength += page.PageName.Length + Separator.Length;

                if (breadCrumbsLength > MaxLength)

                {

                    breadCrumbsText.Insert(0, Separator + "...");

                    break;

                }

                // Insert the link at beginning of the bread crumbs string

                breadCrumbsText.Insert(0, Separator + GetLink(page));

                // Get next visible parent

                page = GetParentPageData(page);

            }

            // Generate the start page link

            string startPageLinkUrl = Server.UrlPathEncode(GetPage(PageReference.StartPage).LinkURL);

            string startPageLink = String.Format(_link, startPageLinkUrl ,  Translate("/navigation/startpagelinktitle"), Translate("/navigation/startpage") );

            // Insert the startpage link and return

            return breadCrumbsText.Insert(0, startPageLink).ToString();

        }

        /// <summary>

        /// Get the next visible parent page of the supplied <see cref="PageData"/>.

        /// </summary>

        /// <param name="page"></param>

        /// <returns>The <see cref="PageData"/> object or    </returns>

        private PageData GetParentPageData(PageData pageData)

        {

            // Don't return a PageData object for start page or root page.

            if (pageData == null || pageData.ParentLink == PageReference.StartPage || pageData.ParentLink == PageReference.RootPage)

            {

                return null;

            }

            // Get Page data for parent page

            pageData = GetPage(pageData.ParentLink);

            if (pageData != null && pageData.VisibleInMenu)

            {

                return pageData;

            }

            // Step up to next parent

            return GetParentPageData(pageData);

        }

 

        /// <summary>

        /// Returns a anchor based on a <see cref="PageData"/> object.

        /// </summary>

        private string GetLink(PageData page)

        {

            string pageName = page.Property["PageName"].ToWebString();

            return string.Format(_link, Server.UrlPathEncode(page.LinkURL), pageName, pageName);

        }

        /// <summary>

        /// A string used to separate the page links (default = " / ")

        /// </summary>

        /// <returns>The breadcrumbs separator string</returns>

        public string Separator

        {

            get { return _separator; }

            set { _separator = value; }

        }

        /// <summary>

        /// Sets the max length on the visible breadcrumb text (default = 60)

        /// </summary>

        public int MaxLength

        {

            get { return _maxLength; }

            set { _maxLength = value; }

        }

    }

}

#60154
Jul 20, 2012 14:43
Vote:
 

If I understand you correctly the actual problems is that "Missing text /navigation/startpage for en]" is outputted?

This is because there's no translation for the text resource key /navigation/startpage and can be fixed by adding it to the english language file in your sites lang folder. If no such file or folder exist you can either create one or copy it from a new EPiServer site with the Alloy templates.

If you on the other hand don't want the start page to be linked to in the breadcrums you can replace the following code:

 // Generate the start page link

string startPageLinkUrl = Server.UrlPathEncode(GetPage(PageReference.StartPage).LinkURL);

string startPageLink = String.Format(_link, startPageLinkUrl ,  Translate("/navigation/startpagelinktitle"), Translate("/navigation/startpage") );

// Insert the startpage link and return

return breadCrumbsText.Insert(0, startPageLink).ToString();

    

with:

return breadCrumbsText.ToString();

    

 

 

 

#60155
Jul 20, 2012 15:46
Vote:
 

Hi Joel,

 

By preference, I dont want it to appear at all, but after trying what you have suggested, the Missing text /navigation/startpage for en still appears.

Where abouts in the english language file do I put it, and what exactly do I have to put? (languageEN.xml I am assuming)

As always, many thanks for your help!

#60156
Jul 20, 2012 16:09
Vote:
 

That's really strange. It looks pretty clear to me that that's where the link to the start page is added. I would fire up the site in debug mode and take a look at what's going on in the code you posted. Removing the snippet that I posted before really, really should work.

Regarding language file should look something like this:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<languages>
  <language name="English" id="en">
    <navigation>
      <help>Help</help>
      <listen>Listen</listen>
      <readmore>Read more</readmore>
      <search>Search</search>
      <skipnavigation>Go to content</skipnavigation>
      <startpage>Start</startpage>
      <startpagelinktitle>To start page</startpagelinktitle>
    </navigation>
  </language>
</languages>

    

#60157
Jul 20, 2012 16:27
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.