Shared Content in Custom Widget
Has anyone looked into rigging their custom widget to have shared content? I have a textbox in my designer, with the editor. But I'd like to be able to pick from shared content like the Generic Content widget.
Thank you
Charles
Hi Richard,
You should use a custom html field, so you can add a content selector and select the shared content block you want.
I have prepared a sample you can use as a base to build your custom field control. I have attached the control to the reply. Please, change the default control type for the field you want to be using the new control from the default HtmlField to the custom control type
Regards,
Nikola Zagorchev
Telerik
What version is the sharedContentSelector available? I'm getting
Telerik.Sitefinity.Web.UI.TemplateException: A required control was not found in
the template for "~/Controls/CustomHtmlField/CustomHtmlField.ascx". The control
must be assignable from type
"Telerik.Sitefinity.Web.UI.ControlDesign.ContentSelector" and must have ID
"sharedContentSelector".
Hi Richard,
The ContentSelector control is available from very old versions, could you please specify your version? Furthermore, the problem is that the control is not found in the template, not that it does not exist as a control. Please, ensure the template is referenced correctly and it is loaded:
"~/Controls/CustomHtmlField/CustomHtmlField.ascx"
<%@ Register Assembly="Telerik.Sitefinity" TagPrefix="designers" Namespace="Telerik.Sitefinity.Web.UI.ControlDesign" %>
...
<
sf:ConditionalTemplate
Left
=
"DisplayMode"
Operator
=
"Equal"
Right
=
"Write"
runat
=
"server"
>
<
sf:ResourceLinks
id
=
"resourcesLinks2"
runat
=
"server"
UseEmbeddedThemes
=
"true"
Theme
=
"Default"
>
<
sf:EmbeddedResourcePropertySetter
Name
=
"Telerik.Sitefinity.Resources.Themes.Default.Styles.EditorDialogs.css"
Static
=
"true"
ControlID
=
"editControl"
ControlPropertyName
=
"DialogsCssFile"
/>
<
sf:ResourceFile
Name
=
"Telerik.Sitefinity.Resources.Themes.Default.Styles.Window.css"
Static
=
"true"
/>
</
sf:ResourceLinks
>
<
asp:Label
ID
=
"titleLabel_write"
runat
=
"server"
CssClass
=
"sfTxtLbl"
AssociatedControlID
=
"editControl"
/>
<
asp:LinkButton
ID
=
"expandLink"
runat
=
"server"
OnClientClick
=
"return false;"
CssClass
=
"sfOptionalExpander"
/>
<%--NewLineBr="False" - removed because of bug 112126. The bug should be fixed in the next release of RadControls.--%>
<
asp:Panel
ID
=
"expandableTarget"
runat
=
"server"
CssClass
=
"sfEditorWrp sfClearfix"
>
<
telerik:RadEditor
ID
=
"editControl"
runat
=
"server"
Skin
=
"Default"
Width
=
"100%"
Height
=
"550px"
EnableResize
=
"False"
EditModes
=
"Design,HTML"
DialogHandlerUrl
=
"~/Telerik.Web.UI.DialogHandler.axd"
Content
=
""
StripFormattingOptions
=
"Css,Font,Span"
>
<
FlashManager
ViewPaths
=
"~/Files"
UploadPaths
=
"~/Files"
DeletePaths
=
"~/Files"
/>
</
telerik:RadEditor
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
onclientclick
=
"return false;"
Text
=
"Select from shared content"
/>
<
div
id
=
"selectorTag"
runat
=
"server"
style
=
"display: none;"
>
<
designers:ContentSelector
ID
=
"sharedContentSelector"
runat
=
"server"
ItemType
=
"Telerik.Sitefinity.GenericContent.Model.ContentItem"
TitleText="<%$Resources:ContentResources, SelectSharedContentYouWantToUse %>"
BindOnLoad="false"
AllowMultipleSelection="false"
WorkMode="List"
SearchBoxInnerText=""
ShowProvidersList="false"
SearchBoxTitleText="<%$Resources:Labels, NarrowByTyping %>"
ListModeClientTemplate="<
span
class
=
'sfItemTitle'
>Title</
span
><
span
class
=
'sf_binderCommand_viewContentPages sfLnk'
>PagesCountUIString</
span
>">
</
designers:ContentSelector
>
</
div
>
Currently on 6.3.5000.
I've double checked those first. If I change the path to the custom control, I get a can not find template file. When I corrected that, it began reporting it can not find the control in the template.
Still does not work. How can I check and verify that the customHtmlField.ascx is loaded? When the application is in debug, I hit the get statement that returns the string in the designers code behind.
Hi Richard,
I checked and the ContentSelector is available in Sitefinity 6.3 and it is in the same namespace - Telerik.Sitefinity.Web.UI.ControlDesign
, please check you are referencing the same type of control in the designer server code, as well.
Regards,
Nikola Zagorchev
Telerik
Hello,
For anyone that might look at this thread, note that it is important when creating the custom field you should initially to use the Rich text editor interface, so it can create all default htmlfield properties for the custom field. Then change the control type to be your custom one, inheriting from HtmlField, in the settings. You can change the control type from Advanced settings -> News -> Controls ->NewsBackend -> Views -> Insert/Edit View ->Sections -> CustomFieldsSection. Select your field and change the type to your custom field control one.
Regards,
Nikola Zagorchev
Telerik