How to make the widget not display the title in front-end UI using programming (not admin UI)

Topics: Customizing Orchard
Apr 30, 2013 at 2:47 AM
Hello,

I'm trying to create a widget using codes (not using admin UI).
I already have the code below and it's working fine. But I can't figure out how to set the settings where the widget title is not displayed in the front-end UI. In admin UI, this is set by checking/unchecking a checkbox. How to do it in codes? Can anyone help me? Thanks!
ContentDefinitionManager.AlterTypeDefinition("ProfileHeaderWidget", cfg => cfg
               .WithPart("ProfileHeaderPart")
               .WithPart("WidgetPart")
               .WithPart("CommonPart")
               .WithSetting("Stereotype", "Widget"));


             var defaultLayer = _widgetsService.GetLayers().First(x => x.Name == "Authenticated");
             var widget = _widgetsService.CreateWidget(defaultLayer.Id, "ProfileHeaderWidget", "", "2", "Header");

       
             _contentManager.Publish(profileWidget.ContentItem);
Coordinator
Apr 30, 2013 at 2:50 AM
It's a setting, that you can set in pretty much the same way you are setting that stereotype... Set it from the admin on a widget, then find its record in the DB and dig into the settings XML. This way, you can figure it out yourself.
Apr 30, 2013 at 2:52 AM
Ok thanks. I got a reply in 3 minutes..nice.
Apr 30, 2013 at 3:44 AM
ok, here's the final working code:
            ContentDefinitionManager.AlterPartDefinition("ProfileHeaderPart", part => part
               .Attachable(false)                                    
               );

         
            ContentDefinitionManager.AlterTypeDefinition("ProfileHeaderWidget", cfg => cfg
               .WithPart("ProfileHeaderPart")
               .WithPart("WidgetPart")
               .WithPart("CommonPart")
               .Creatable(false)
               .WithSetting("Stereotype", "Widget"));   
                

             var defaultLayer = _widgetsService.GetLayers().First(x => x.Name == "Authenticated");
             var widget = _widgetsService.CreateWidget(defaultLayer.Id, "ProfileHeaderWidget", "Profile Header", "2", "Header");
             widget.RenderTitle = false;
This code looks magic to me: 'widget.RenderTitle = false'.
There's no code that updates the db, yet it seems to be updating the change back to the db.

Anyways, thanks BertrandLeRoy..
Developer
Apr 30, 2013 at 10:34 AM
There is change tracking going on by means of entity class proxies (NHibernate generated).
When you set a property on an entity (as you're doing when setting widget.RenderTitle), this change is monitored.
At the end of the HTTP request, all changes are persisted to the DB.
May 2, 2013 at 12:36 PM
ok thanks.