2
Vote

Feature Request: Default Content on Page Types should be localizable

description

The content defined in placeholders under Default Content is not language-specific and is therefor next to useless on multi-language websites, since you'll end up getting ie. danish content on your new pages even when the page just created is in Russian.

comments

mawtex wrote Jul 12, 2012 at 6:00 PM

Default content is very useful since it allows devs to have predefined C1 Function calls and HTML structures (like some intricate <table /> setup). We never actually intended this for writing std. texts, but I guess that can be used as well.

What is the use case (what type of content is it that should be templated this way)?

burningice wrote Jul 12, 2012 at 6:14 PM

Its several templates, each having 10 placeholders where there will be a <h1 /> title in each of them when creating a page. The title is of course language specific. So far it has been handled by duplicating the same structure of the current DefaultPlaceholderContent but just making it localizable. The following code listens of OnAfterAdd on IPage and manages the insertion of default content.

private static void DataEventsHandler_OnAfterAdd(object sender, DataEventArgs e)
    {
        var page = e.GetData<IPage>();

        if (page.DataSourceId.PublicationScope == PublicationScope.Unpublished)
        {
            foreach (var ci in DataLocalizationFacade.ActiveLocalizationCultures)
            {
                if (!ci.Equals(page.DataSourceId.LocaleScope))
                {
                    using (var data = new DataConnection(ci))
                    {
                        if (data.Get<IPagePlaceholderContent>().Any(p => p.PageId == page.Id))
                        {
                            return;
                        }
                    }
                }
            }

            IDictionary<string, IDictionary<string, string>> dict;
            if (_defaultContent.TryGetValue(page.PageTypeId, out dict))
            {
                using (var data = new DataConnection())
                {
                    foreach (var kvp in dict[page.CultureName])
                    {
                        var placeholder = data.CreateNew<IPagePlaceholderContent>();

                        placeholder.PageId = page.Id;
                        placeholder.PlaceHolderId = kvp.Key;
                        placeholder.Content = kvp.Value;

                        data.Add(placeholder);
                    }
                }
            }
        }
    }

wrote Jul 23, 2012 at 6:53 AM

wrote Feb 22, 2013 at 12:21 AM