Take the community feedback survey now.

Fake content on page in CMS UI

Vote:
 

Hi! Not even chatgpt can help me with this. 

How can i make this content "a guid" show up in the backend ui? 

    [ScaffoldColumn(true)]
    [Editable(false)]
    [Display(Order = -100)]
    public virtual string SomeFakeId
    { get { return "a guid"; } set { /*not possible*/ } }

or 

    [ScaffoldColumn(true)]
    [Editable(false)]
    [Display(Order = -100)]
    public virtual string SomeFakeId
    { get => "a guid";  set => this.SetPropertyValue(p => p.SomeFakeId, value); }


 

At later stage, ""a guid" will be replaced by other content. 

    [ScaffoldColumn(true)]
    [Editable(false)]
    [Display(Order = -100)]
    public virtual string SomeFakeId
    { get => JsonSerializer.Deserialize<CustomModel>(this.GetPropertyValue(p => p.JsonField))?.id;  set => this.SetPropertyValue(p => p.SomeFakeId, value); } //this do not work. 

no editor descriptor solution wanted. 

#340873
Edited, Oct 31, 2025 10:30
Vote:
 

Assuming you actually want to store the fake id in the database when saving the page

public override void SetDefaultValues(ContentType contentType)
{
	base.SetDefaultValues(contentType);
	SomeFakeId = Guid.NewGuid().ToString();
}

This should be posted on the actual Page or BlockType implementation.

You may also achieve this using content events, while that value may not be visible directly after page creation due to the immutable nature of content in CMS.

#340877
Edited, Oct 31, 2025 18:23
Vote:
 

Hej Eric, no i do not want to save it, just show in the UI. 

SetDefault is only run on creations as you mention. Not applicable. 

Other ideas?

#340882
Nov 03, 2025 12:13
Vote:
 

AFAIK that is your only option.

Set a standard shared fake value using SetDefaultValues that is removed when submitting via an event.

Fun fact realized when testing this

private const string TestFieldDefaultValue = "Hello World!";
[Display(Order = 650)]
public virtual string TestField
{
    get
    {
        var val = this.GetPropertyValue(b => b.TestField);
        return string.IsNullOrWhiteSpace(val) ? TestFieldDefaultValue : val;
    }
    set => TestField = value;
}

The code above will

  1. actually show the TestFieldDefaultValue in the view but not in the edit gui
  2. not store the TestFieldDefaultValue in the database

Other things tried

DefaultValue attribute approach. Arguably the DefaultValue should be implemented as a convenience for developers using SetDefaultValues under the hood. No effect on either the gui or in the view and isn't stored in the database.

[Display(Order = 650)]
[DefaultValue("Hello World!")] // does not work
public virtual string TestField { get; set; }

Using auto-property initializers doesn't work either. No effect on either the gui or in the view and isn't stored in the database.

[Display(Order = 650)]
public virtual string TestField { get; set; } = "Hello World!"; // does not work

The values in the examples above is assigned when a new instance of the containing class is created. If you set the property to another value later (e.g., in a constructor or method), it will override the initializer. Thus the behaviour clearing these values since optimizely reinitializes all properties when creating a new instance. The first example using this.GetPropertyValue(b => b.TestField); will display its value in the view since it is evaluated and executed during runtime. And I assume that the CMS Gui don't use the same process when picking up values.

#340883
Edited, Nov 03, 2025 13:46
* 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.