Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Custom Property not rendering as expected

Vote:
 

I'm trying to implement a custom property, much like this one: https://gregwiechec.com/2016/05/textarea-with-statistics/

Template file DojoProperty2.html:

I'm alive!!
Characters: 0
Words: 0
Lines: 1

Looks like this if I open the file in the browser:

But in the CMS I only get this:

DojoProperty.js:

define([
    "dojo/_base/declare",
    "dijit/_Widget",
    "dijit/_TemplatedMixin",
    'dojo/text!./DojoProperty2.html',
],
    function (
        declare,
        _Widget,
        _TemplatedMixin,
        template
    ) {
        return declare("jondjones.CustomProperty.DojoProperty", [
            _Widget,
            _TemplatedMixin], {
                templateString: template
            }
        );
    }
);

DojoPropertyEditorDescriptor.cs:

using EPiServer.Shell.ObjectEditing.EditorDescriptors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TemplateTest.Business.EditorDescriptors
{
    [EditorDescriptorRegistration(
            TargetType = typeof(String),
            UIHint = "CustomProperty")]
    public class DojoPropertyDescriptor : EditorDescriptor
    {
        public DojoPropertyDescriptor()
        {
            ClientEditingClass = "alloy/editors/DojoProperty";
        }
    }
}

TeaserBlock.cs: (where the property is being used)

using System.ComponentModel.DataAnnotations;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Web;

namespace TemplateTest.Models.Blocks
{
    /// 
    /// Used to provide a stylized entry point to a page on the site
    /// 
    [SiteContentType(GUID = "EB67A99A-E239-41B8-9C59-20EAA5936047")] // BEST PRACTICE TIP: Always assign a GUID explicitly when creating a new block type
    [SiteImageUrl] // Use site's default thumbnail
    public class TeaserBlock : SiteBlockData
    {
        [Display(
            Name = "Custom Property3",
            Description = "Custom Property Desc3",
            GroupName = SystemTabNames.Content,
            Order = 1)]
        [UIHint("CustomProperty3")]
        public virtual string CustomProperty3 { get; set; }

        [CultureSpecific]
        [Required(AllowEmptyStrings = false)]
        [Display(
            GroupName = SystemTabNames.Content,
            Order = 1)]
        public virtual string Heading { get; set; }

        [CultureSpecific]
        [Required(AllowEmptyStrings = false)]
        [Display(
            GroupName = SystemTabNames.Content,
            Order = 2)]
        [UIHint(UIHint.Textarea)]
        public virtual string Text { get; set; }

        [CultureSpecific]
        [Required(AllowEmptyStrings = false)]
        [UIHint(UIHint.Image)]
        [Display(
            GroupName = SystemTabNames.Content,
            Order = 3)]
        public virtual ContentReference Image { get; set; }

        [Display(
            GroupName = SystemTabNames.Content,
            Order = 4)]
        public virtual PageReference Link { get; set; }
    }
}

TeaserBlock.cshtml:

@using EPiServer.Core
@using TemplateTest.Controllers
@model TeaserBlock

@Html.PropertyFor(m => m.CustomProperty3)

@*Link the teaser block only if a link has been set and not displayed in preview*@ @using (Html.BeginConditionalLink( !ContentReference.IsNullOrEmpty(Model.Link) && !(ViewContext.Controller is PreviewController), Url.PageLinkUrl(Model.Link), Model.Heading)) {

x.Heading)>@Model.Heading

x.Text)>@Model.Text

x.Image)>
}

What am I doing wrong?

Version: 11.10.1.0

#198912
Nov 08, 2018 13:43
Vote:
 

Hi Beatrice,

How does your module.config look?

/Jake

#198917
Nov 08, 2018 18:03
Vote:
 

In your model, you have:

[UIHint("CustomProperty3")]
public virtual string CustomProperty3 { get; set; }

Should this be "CustomProperty3" as UIHint instead of "CutomProperty" from EditorDescriptor?

#198918
Nov 08, 2018 21:20
Vote:
 

This is what it looks like:

<?xml version="1.0" encoding="utf-8"?>
<module>
    <assemblies>
	    <!-- This adds the Alloy template assembly to the "default module" -->
        <add assembly="TemplateTest" />
    </assemblies>
    <clientResources>
        <add name="epi-cms.widgets.base" path="Styles/Styles.css" resourceType="Style"/>
    </clientResources>
    <dojo>
        <!-- Add a mapping from alloy to ~/ClientResources/Scripts to the dojo loader configuration -->
        <paths>
            <add name="alloy" path="Scripts" />
        </paths>
    </dojo>
</module>
#198942
Nov 09, 2018 10:37
Vote:
 
#198943
Nov 09, 2018 10:37
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.