Copied to clipboard

Flag this post as spam?

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


  • Claudio Ridolfi 11 posts 62 karma points
    Jun 11, 2015 @ 12:13
    Claudio Ridolfi
    0

    Usage with grids

    Hi, I'm trying to use polyglot on a new website which use the grid layout, but i'm facing a problem. I just can't use the "Translated Property" macro as it is, since the grid must be rendered, how could I take the translated property and then render it?

    I thought an easy way would be to use tabs for the translations, and then pass to GetGridHtml the different content depending on the selected language, how would i retrieve the right property alias for the currently selected language?

  • dimi309 245 posts 579 karma points
    Jun 13, 2015 @ 12:24
    dimi309
    0

    Hello,

    I am not very familiar with the grid layout so I am not sure that this will solve the problem, but how about trying to use PropertyReferenceTranslation? For an example you can have a look at the TranslatedNavigation source:

    https://github.com/dimitrikourk/Polyglot/blob/v2/Dimi.Polyglot/UmbracoRazorScripts/TranslatedNavigation.cshtml

  • Claudio Ridolfi 11 posts 62 karma points
    Jun 13, 2015 @ 16:49
    Claudio Ridolfi
    1

    Well, I found that the easier and best way would be just to modify PropertyTranslation, using GetGridHtml to return the property value, now is just Umbraco.Web.GridTemplateExtensions.GetGridHtml that is giving me headaches!

  • dimi309 245 posts 579 karma points
    Jun 13, 2015 @ 18:23
    dimi309
    0

    Hmmm.... Sadly I am not familiar with this grid thing... But if there is anything else I can help you with, as far as Polyglot is concerned, let me know!

  • Claudio Ridolfi 11 posts 62 karma points
    Jun 13, 2015 @ 21:23
    Claudio Ridolfi
    100

    I did it, here's the result, for anyone who will need:

    @ * PropertyTranslationGetGrid.cshtml *@

    @inherits umbraco.MacroEngines.DynamicNodeContext @using umbraco.MacroEngines; @{

    string selectedLanguage = RenderPage("SelectedLanguage.cshtml").ToString().Trim();
    string selectedLanguageNoDash = selectedLanguage.Replace("-", string.Empty);
    
    DynamicNode page = Model;
    var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
    
    var contentFound = false;
    
    if (page.HasProperty(Parameter.Property + selectedLanguageNoDash) && !string.IsNullOrEmpty(page.GetPropertyValue(Parameter.Property + selectedLanguageNoDash)))
    {
        contentFound = true;
        @Html.Raw(Umbraco.Web.GridTemplateExtensions.GetGridHtml(umbracoHelper.TypedContent(page.Id),Parameter.Property + selectedLanguageNoDash,Parameter.Framework))
    }
    
    if (!contentFound)
    {
        foreach (DynamicNode child in page.GetChildrenAsList)
        {
            if (child.NodeTypeAlias == page.NodeTypeAlias + "TranslationFolder")
            {
                foreach (DynamicNode translation in child.GetChildrenAsList)
                {
                    var language = translation.GetPropertyValue("language");
    
                    if (language != null && language.ToString().ToLower() == selectedLanguage.ToLower())
                    {
                        if (translation.HasProperty(Parameter.Property) && !string.IsNullOrEmpty(translation.GetPropertyValue(Parameter.Property)))
                        {
                            contentFound = true;
                            @Html.Raw(Umbraco.Web.GridTemplateExtensions.GetGridHtml(umbracoHelper.TypedContent(translation.Id),Parameter.Property,Parameter.Framework))
                        }
                    }
                }
            }
        }
    }
    
    if (!contentFound)
    {
    
        if (page.HasProperty(Parameter.Property) && !string.IsNullOrEmpty(page.GetPropertyValue(Parameter.Property)))
        {
            @Html.Raw(Umbraco.Web.GridTemplateExtensions.GetGridHtml(umbracoHelper.TypedContent(page.Id),Parameter.Property,Parameter.Framework))
        }
    }
    

    }

    The new parameter 'Framework' is for the grid renderer

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies