Custom filed in Navigation Widget
Please let me know if i can add a custom field in default navigation widget designer ?
I want to add field which should be populated in the Navigation widget designer.When i edit Navigation widget, designer should have extra field like CSS class, which can be mapped to my Navigation widget template.
Thanks,
Arun
Hi Arun,
You can create a custom field for the Pages, for example 'CustomClass'. Then you would create a custom Navigation template where you could use code-behind or even within the markup itself to bind the value of this custom field to the markup.
An example on how to do this within the code-behind:
protected
void
NavigationContainer_ItemDataBound(
object
sender, NavigationContainerItemEventArgs e)
var node = e.Item.DataItem
as
PageSiteNode;
if
(node ==
null
)
return
;
var manager = PageManager.GetManager(PageManager.GetDefaultProviderName());
if
(manager ==
null
)
return
;
var page = manager.GetPageNode(node.Id);
if
(page ==
null
)
return
;
var iconClass = page.GetValue<
string
>(
"IconClass"
);
if
(iconClass.IsNullOrEmpty())
return
;
var lnkItem = e.Item.FindControl(
"lnkItem"
)
as
HtmlAnchor;
if
(lnkItem ==
null
)
return
;
lnkItem.Attributes.Remove(
"class"
);
lnkItem.Attributes.Add(
"class"
,
string
.Concat(
"icon icon-"
, iconClass));
lnkItem.Attributes.Add(
"title"
, page.Title);
Best regards,
Daniel
Hi Daniel,
Thanks for you reply,
I will be bale to create custom field for pages and can access the same in navigation templates,
But i want the custom field to be added in the Navigation widget or a new field with drop down values to be added in the navigation widget designer like "cssclass" and i can sort the navigation design according to the value provided by the user.
Thanks,
Arun
Hi,
Please let me know if I can customize the default Navigation widget designer, eg. can i change the cssclass to dropdown populated with few default values.
Thanks,
Arun
Hi Arun,
Wouldn't the default CSS Class field available in the Navigation widget suffice for your needs?
If you really need to customize the default Navigation widget designer you will need to override some of the base classes in order to introduce your customization.
1. First you need to inhering from our default LightNavigationControl class (the Navigation widget).
2. For the designer you need to inherit from LightNavigationDesigner
3. You need to reference this custom designer from the custom navigation control from step 1 like so:
[ControlDesigner(
typeof
(CustomLightNavigationDesigner))]
public
class
CustomLightNavigationControl : LightNavigationControl
................