+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Getting localized content in custom module

Getting localized content in custom module

3 posts, 1 answered
  1. Rein
    Rein avatar
    22 posts
    Registered:
    07 Oct 2008
    20 Sep 2012
    Link to this post
    I have created a custom module, based on the Real Estate Agents module from the SDK. I added a custom field named "JobDescription" in my model and I'm having trouble getting the localized content from this field in my frontend widget. It only shows the translation from default language. The values are persisted because they show up correctly in the backend. Any ideas on how to fix this? Below is the relevant code.

    [DataMember]
    [FieldAlias("jobDescription")]
    [ScaffoldInfo(@"<sitefinity:HtmlField runat=""server"" DisplayMode=""Read"" Value='<%# Eval(""JobDescription"")%>' />")]
    [UserFriendlyDataType(UserFriendlyDataType.LongText)]
    [MetadataMapping(true, true)]
    [MultilingualProperty]
    public virtual Lstring JobDescription
    {
        get
        {
            if (this.jobDescription == null)
                this.jobDescription = this.GetString("JobDescription");
            return this.ApplyContentFilters(this.jobDescription);
        }
        set
        {
            this.jobDescription = value;
            this.SetString("JobDescription", this.jobDescription);
        }
    }
    [Transient]
    private Lstring jobDescription;

    Item mapping:
    itemMapping.HasProperty(p => p.JobDescription).IsLongText(this.Context);

    Copy method:
    destination.GetString("JobDescription").CopyFrom(source.GetString("JobDescription"));

    Resources:
    [ResourceEntry("JobDescription",
            Value = "JobDescription",
            Description = "JobDescription",
            LastModified = "2010/12/03")]
            public string JobDescription
            {
                get
                {
                    return this["JobDescription"];
                }
            }

    Viewmodel constructor:
    this.jobDescription = contentItem.JobDescription;

    Viewmodel property:
    public string JobDescription
            {
                get { return this.jobDescription; }
                set { this.jobDescription = value; }
            }
            private string jobDescription;

    Definitions:
    var jobDescriptionField = new HtmlFieldElement(mainSection.Fields)
    {
        ID = "jobDescriptionFieldControl",
        DataFieldName = displayMode == FieldDisplayMode.Write ? "JobDescription.PersistedValue" : "JobDescription",
        DisplayMode = displayMode,
        Title = "JobDescription",
        CssClass = "sfFormSeparator sfContentField",
        ResourceClassId = typeof(VacancyResources).Name,
        WrapperTag =  HtmlTextWriterTag.Li,
        EditorContentFilters = Telerik.Web.UI.EditorFilters.DefaultFilters,
        EditorStripFormattingOptions = (EditorStripFormattingOptions?)(EditorStripFormattingOptions.MSWord | EditorStripFormattingOptions.Css | EditorStripFormattingOptions.Font | EditorStripFormattingOptions.Span | EditorStripFormattingOptions.ConvertWordLists)
    };
    mainSection.Fields.Add(jobDescriptionField);

    Frontend listview:
    <sf:FieldListView ID="jobDescription" runat="server" Text="{0}" Properties="JobDescription" WrapperTagName="div" />

    Thanks in advance for your replies!
  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    20 Sep 2012
    Link to this post
    Hi Rein,

    I don't think you should setup a mapping for a LString field. (=> item-mapping)
    Only if you want to persist items you don't translate or integer, datetime fields etc.

    Regards,
    Daniel
    Answered
  3. Rein
    Rein avatar
    22 posts
    Registered:
    07 Oct 2008
    20 Sep 2012
    Link to this post
    Thanks Daniel! Works like a charm!
3 posts, 1 answered