How to know what type for dynamic content?

Posted by Community Admin on 04-Aug-2018 20:27

How to know what type for dynamic content?

All Replies

Posted by Community Admin on 01-Apr-2014 00:00

I have a custom content type I created in the backend. Now I am accessing that type in a widget. I have several fields all as short text, but they are not strings? They are Lstring? I added another field that is also short text but when I load the widget it says it is not Lstring?

How can I know what to depend on here? Is there a list of what types are associated with which fields? How can short text sometimes be Lstring and sometimes not? I'm baffled by how some of this software works. After 2 days I've come across numerous of these head scratchers. Also, why even use a custom string type? What is wrong with C# string?

Posted by Community Admin on 01-Apr-2014 00:00

Here is the code....all fields are just short text, but Title is saying that Lstring is incorrect type:

var dynamicTestimonial = dynamicRepository.GetByID(id);
var name = dynamicTestimonial.GetValue<Lstring>("Name");
var title = dynamicTestimonial.GetValue<Lstring>("Title");
var company = dynamicTestimonial.GetValue<Lstring>("Company");

Posted by Community Admin on 01-Apr-2014 00:00

Hi Ryan,

Have you tried setting your properties to string types instead of vars? Here's a working sample that I have in my dynamic content type model:

public string Title get; set;

public AnnouncementsModel(DynamicContent sfAnnouncementsItem)

            this.Title = sfAnnouncementsItem.GetValue<Lstring>("Title");


Also, make sure you have the following using statement in your code:

using Telerik.Sitefinity.Model;

Regards,
David C
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 02-Apr-2014 00:00

The implicit typing is not the issue. Is there a reference where I can see the types for each field? It's hard for a developer to assume a string field is going to be reflected as a custom string type Lstring. I'm afraid further widgets I'm building are going to have me banging my head against  a wall guessing what type it's going to want me to cast to.

Posted by Community Admin on 02-Apr-2014 00:00

Hello,

The Lstring designates this field as being set to "localizable". Check your custom module text field's "More Options" section to see if the "Make localizable" checkbox is selected. If it isn't then you can use string. If it is, then you must use Lstring.

You can find more information here:

~ www.sitefinity.com/.../undesirable-behavior-dynamiccontent-getvalue-t-(string)

www.sitefinity.com/.../webframe.html

www.sitefinity.com/.../topic132783.html

Regards,

David C
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed