Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Wihlborg Inge 21 posts 161 karma points
    Aug 28, 2018 @ 13:48
    Wihlborg Inge
    0

    Hi, I am using Vorto in a site, based on Umazel Starter Kit, to translate the content to different cultures but I cannot figure out how to translate the breadcrumbs.

    In PageBreadcrumb.cshtml there are a call to GetPageTitleForBreadcrum() and I can not find that function, maybe it is hidden in a DLL file.

    What does the function do and if it is possible to change it or override the function in any way.

    BR Inge

  • Sotiris Filippidis 286 posts 1501 karma points
    Aug 28, 2018 @ 17:58
    Sotiris Filippidis
    100

    Yes, those functions are in a DLL. But it's not very complicated. It returns the value of the altTitleBreadcrumb property, defaulting to either the overrideTitle field's value if it has one, or the node's name if everything else is empty. You can probably implement your own logic there.

  • Wihlborg Inge 21 posts 161 karma points
    Sep 05, 2018 @ 09:13
    Wihlborg Inge
    0

    Thanks then I will try to implement my own logic instead as you suggested.

  • Wihlborg Inge 21 posts 161 karma points
    Sep 14, 2018 @ 12:56
    Wihlborg Inge
    0

    Hi again, when going furthed I found the function GetPageTitleForMenu() that is used for navigation. Could you please also explain what that method does as I am also going to translate the page names.

    Best Inge

  • Sotiris Filippidis 286 posts 1501 karma points
    Sep 14, 2018 @ 15:37
    Sotiris Filippidis
    0

    I'm really sorry to see you struggle like this - it wasn't my intention! Best I can do is provide the code for those extension methods that bother you so you can take it from there.

    using System;
    using System.Web;
    using umbraco.NodeFactory;
    using Umbraco.Core.Models;
    using System.Reflection;
    using Umbraco.Web;
    
    /// <summary>
    /// Summary description for Extensions
    /// </summary>
    /// 
    namespace DotSee.UmbracoExtensions
    { 
    
    public static class PageTitles
    {
    
        #region Titles, metas etc.
    
        /// <summary>
        /// Gets the page name, or the value of the overrideTitle field if it is not empty
        /// </summary>
        /// <param name="currPage">The IPublishedContent that is extended</param>
        /// <returns>The page name, or an error string if the overrideTitle field is not found.</returns>
        public static string GetPageName(this IPublishedContent currPage)
        {
            string retVal = "[[:ERROR:overrideTitle property not found]]";
            try
            {
                if (currPage.HasProperty("overrideTitle"))
                {
                    retVal = string.IsNullOrEmpty(currPage.GetPropertyValue<string>(Constants.OverrideTitlePropName)) ? currPage.Name : currPage.GetPropertyValue<string>(Constants.OverrideTitlePropName);
                }
            }
            catch (Exception ex)
            {
                Umbraco.Core.Logging.LogHelper.Error(
                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType
                , string.Format("Fatal exception on page id:{0}, doctype:{1}", currPage.Id.ToString(), currPage.DocumentTypeAlias)
                ,ex);
    
                throw (ex);
            }
            return (retVal);
        }
    
        /// <summary>
        /// Gets the page name, or the value of the overrideTitle field if it is not empty
        /// </summary>
        /// <param name="umb">The UmbracoHelper object that is extended</param>
        /// <returns>The page name, or an error string if the overrideTitle field is not found.</returns>
        public static string GetPageName(this UmbracoHelper umb)
        {
            IPublishedContent currPage = umb.TypedContent(UmbracoContext.Current.PageId);
    
            return (currPage.GetPageName());
        }
    
            /// <summary>
            /// Get the title for the page, to display inside the HTML markup - returns either the contents of the altTitle field or the page name if altTitle is empty.
            /// (include @using WebSite at the top of the page)
            /// </summary>
            /// <param name="currPage">@currPage object</param>
            /// <returns>Page's title</returns>
            public static string GetPageTitleInternal(this IPublishedContent currPage)
            {
                if (currPage == null) { return null; }
    
                string retVal = currPage.GetPropertyValueOrDefault(Constants.AltTitleInternalPropName);
                if (string.IsNullOrEmpty(retVal))
                {
                    retVal = currPage.GetPropertyValueOrDefault(Constants.OverrideTitlePropName);
                }
                return (retVal);
            }
    
    
            /// <summary>
            /// Gets the title for the page, in order to use it in HTML markup - returns either the contents of the altTitle field or the page name if altTitle is empty.
            /// </summary>
            /// <param name="umb">The UmbracoHelper instance</param>
            /// <returns></returns>
            public static string GetPageTitleInternal(this UmbracoHelper umb)
        {
    
            IPublishedContent currPage = umb.TypedContent(UmbracoContext.Current.PageId);
    
            return (currPage.GetPageTitleInternal());
    
        }
    
        /// <summary>
        /// Gets an alternative title for menus - uses overrideTitle or page name if the altTitle menu field is empty
        /// </summary>
        /// <param name="currPage">The IPublishedContent that is extended</param>
        /// <returns>Contents of altTitleMenu, or contents of overrideTitle if altTitle menu is empty or contents of page name if all are empty</returns>
        public static string GetPageTitleForMenu (this IPublishedContent currPage)
        {
    
            return (currPage.GetPropertyValueOrDefault(Constants.AltTitleMenuPropName));
        }
    
        /// <summary>
        /// Gets an alternative title for menus - uses overrideTitle or page name if the altTitle menu field is empty
        /// </summary>
        /// <param name="umb">The UmbracoHelper instance that is extended</param>
        /// <returns>Contents of altTitleMenu, or contents of overrideTitle if altTitle menu is empty or contents of page name if all are empty</returns>
        public static string GetPageTitleForMenu(this UmbracoHelper umb)
        {
            IPublishedContent currPage = umb.TypedContent(UmbracoContext.Current.PageId);
    
            return (currPage.GetPageTitleForMenu());
        }
    
        /// <summary>
        /// Get the title for the breadcrumb (include @using WebSite at the top of the page)
        /// </summary>
        /// <param name="currPage">The IPublishedContent representing the current page</param>
        /// <returns>Pages' title for the breadcrumb</returns>
        public static string GetPageTitleForBreadcrumb(this IPublishedContent currPage)
        {
    
                if (currPage == null) { return null; }
                try
            {
                return (currPage.GetPropertyValueOrDefault(Constants.AltTitleBreadcrumbPropName));
            }
            catch (NullReferenceException ex)
            {
    
                Umbraco.Core.Logging.LogHelper.Error(MethodBase.GetCurrentMethod().DeclaringType, "altTitleBreadcrumb property not found", ex);
                return ("ERROR:altTitleBreadcrumb property not found");
            }
    
        }
    
    
    
            /// <summary>
            /// Gets the meta title for a given page, returns the page's name if no meta title is found.
            /// </summary>
            /// <param name="thePage">The page we need the meta title for</param>
            /// <returns>String</returns>
            public static string GetPageMetaTitle(this IPublishedContent thePage)
        {
            string metaTitle = GetMetaTitle(thePage);
            if (string.IsNullOrEmpty(metaTitle))
            {
                metaTitle = thePage.GetPageName();
            }
            return (metaTitle);
        }
    
        /// <summary>
        /// Gets the meta description for the given page, returns the home page's meta description if empty
        /// </summary>
        /// <param name="HomePage">The home page</param>
        /// <param name="currPage">The current page</param>
        /// <returns>String</returns>
        public static string GetPageMetaDescription(this IPublishedContent currPage, IPublishedContent HomePage)
        {
            string metaDescription = string.Empty;
    
            //Get meta description for current page
            metaDescription = GetMetaDescription(currPage);
    
            //If no description there, get meta description from home page
            if (string.IsNullOrEmpty(metaDescription))
            {
                metaDescription = GetMetaDescription(HomePage);
            }
    
            return (metaDescription);
        }
    
        /// <summary>
        /// Gets the meta keywords for the given page, returns the home page's meta keywords if empty
        /// </summary>
        /// <param name="HomePage">The home page</param>
        /// <param name="currPage">The current page</param>
        /// <returns>String</returns>
        public static string GetPageMetaKeywords(this IPublishedContent HomePage, IPublishedContent currPage)
        {
            string metaKeywords = string.Empty;
    
            //Get meta description for current page
            metaKeywords = GetMetaKeywords(currPage);
    
            //If no description there, get meta description from home page
            if (string.IsNullOrEmpty(metaKeywords))
            {
                metaKeywords = GetMetaKeywords(HomePage);
            }
    
            return (metaKeywords);
        }
    
        /// <summary>
        /// Gets a property value for the page, defaulting to the page's name or a default string. 
        /// </summary>
        /// <param name="currPage">The page for which we need the property</param>
        /// <param name="propertyName">The property's name</param>
        /// <param name="defaultValue">The default value to be retuned if the property value is empty. If a value is not set, then the page's name is returned.</param>
        /// <returns>An error string if the property doesn't exist, the default value if the property is empty and a default value is set, the page's name if the property is empty and a default value is not set, or the property's value</returns>
        private static string GetPropertyValueOrDefault(this IPublishedContent currPage, string propertyName, string defaultValue=null)
        {
                if (currPage == null) { return null; }
    
            string retVal = string.Format("[[:ERROR:{0} property not found]]", propertyName);
    
            try
            {
                if (currPage.HasProperty(propertyName))
                {
                    retVal = string.IsNullOrEmpty(currPage.GetPropertyValue<string>(propertyName)) ? (defaultValue==null ? currPage.GetPageName() : defaultValue) : currPage.GetPropertyValue<string>(propertyName);
                }
            }
            catch (Exception ex)
            {
                Umbraco.Core.Logging.LogHelper.Error(
                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType
                , string.Format("Fatal exception on page id:{0}, doctype:{1}, name:{2}", currPage.Id.ToString(), currPage.DocumentTypeAlias, currPage.Name)
                , ex);
    
                throw (ex);
            }
    
            return (retVal);
        }
    
        #region Private Methods
    
        /// <summary>
        /// Gets the meta description for the given page, logs an exception and returns an empty string if no meta description is found
        /// </summary>
        /// <param name="thePage">The page for which we need the meta description</param>
        /// <returns>String</returns>
        private static string GetMetaDescription(IPublishedContent thePage)
        {
    
            return (thePage.GetPropertyValueOrDefault(Constants.MetaDescriptionPropName,""));
        }
    
        /// <summary>
        /// Gets the meta keywords for the given page, logs an exception and returns an empty string if no meta keywords is found
        /// </summary>
        /// <param name="thePage">The page for which we need the meta keywords</param>
        /// <returns>String</returns>
        private static string GetMetaKeywords(IPublishedContent thePage)
        {
    
            return (thePage.GetPropertyValueOrDefault(Constants.MetaKeywordsPropName,""));
        }
    
        /// <summary>
        /// Gets the meta title for the given page, returns empty string and logs an exception if no metaTitle property is found
        /// </summary>
        /// <param name="thePage">The page we need the meta title for</param>
        /// <returns>String</returns>
        private static string GetMetaTitle(IPublishedContent thePage)
        {
            return (thePage.GetPropertyValueOrDefault(Constants.MetaTitlePropName));
        }
    
    
        #endregion
    
        #endregion
    
    }
    
    }
    

    And the constants:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace DotSee.UmbracoExtensions
    {
        public static class Constants
        {
            public const string PageHomeDocTypeName = "pageHome";
            public const string ConfigGlobalSettingsDocTypeName = "configGlobalSettings";
    
            public const string UmbracoNaviHidePropName = "umbracoNaviHide";
            public const string PagePrefix = "page";
    
            public const string InternalLinkPropName = "internalLink";
            public const string ExternalLinkPropName = "externalLink";
    
            public const string OverrideTitlePropName = "overrideTitle";
            public const string AltTitleInternalPropName = "altTitleInternal";
            public const string AltTitleMenuPropName = "altTitleMenu";
            public const string AltTitleBreadcrumbPropName = "altTitleBreadcrumb";
    
            public const string AddSuffixPropName = "addSuffix";
            public const string SiteNamePropName = "siteName";
    
            public const string MetaTitlePropName = "metaTitle";
            public const string MetaDescriptionPropName = "metaDescription";
            public const string MetaKeywordsPropName = "metaKeywords";
    
    
    
            public const string RedirectToUrlPropName = "redirectToUrl";
            public const string RedirectFirstSubPagePropName = "redirectFirstSubPage";
        }
    }
    
  • Wihlborg Inge 21 posts 161 karma points
    Sep 17, 2018 @ 09:10
    Wihlborg Inge
    0

    Thanks Sotiris, great showing us what those methods does, I myself managed to solve my issue without rewriting your methods just by adding a If clause.

    foreach (string breadcrumbId in breadcrumbIds)
    {
        int id = int.Parse(breadcrumbId);
        if (id > 0)
        {
            //If we have a "currPage" viewdata item, then the last node in the path is NOT the actual last node.
            //This is due to inheritance - we've inherited background images from the current page (portfolio or blog) so the model is the
            //portfolio or blog's root page, but we need to show the actual item in the path too.
            bool isLast = breadcrumbId.Equals(breadcrumbIds.Last()) && ViewData["currPage"] == null;
    
            IPublishedContent item = Umbraco.TypedContent(id);
    
            var breadcrumb = item.Name;
            var translatedBreadcrumb = item.GetVortoValue("pageName", fallbackCultureName: "en");
    
            if (translatedBreadcrumb != null)
            {
                breadcrumb = translatedBreadcrumb.ToString();
            }
            else
            {
                breadcrumb = item.GetPageTitleForBreadcrumb(); // Using the method in the Starter Kit
            }
    
            if (item.IsVisible() && !isLast)
            {
                <a href="@Umbraco.NiceUrl(id)">@breadcrumb</a> @Html.Raw("/ ");
            }
            if (isLast)
            {
                <span>@breadcrumb</span>
            }
        }
    }
    

    Thanks anyway and keep up the good job supporting us.

    BR Inge

Please Sign in or register to post replies

Write your reply to:

Draft