Home | Blog | Web Development | Instructions for Creating a Feather (MVC) widget

Instructions for Creating a Feather (MVC) widget

May 24, 2016, 14:27 PM | Published under Web Development by April Grimsley

These instructions are for a Feather (MVC) widget, but you’d retrieve the same value if you were using a regular Sitefinity widget. Skip to the code

Let’s suppose, for the sake of illustration, you've a dynamic module with a multiple choice field for choosing the color -- maybe a hero image that has some text and a "learn more" button over top of it.

modulebuilder (new) 

Your fields would be something like this:

  • Related media field called Image
  • Short text field called Headline
  • Short text field called Learn More URL
  • Choices field called Button Color

The client is going to want to make sure that the button color is going to match the background. It would be really difficult to see a light blue button over a picture of a clear blue sky, for example. So it’s important to give the client some button color options that they can select from. One of those options is labeled Dark Blue with a value of dkblue. The plan here is that you are going to get the value from the button color field, because the values of the color selection options correspond to CSS classes for the buttons.

@item.Fields.Color will give you "Dark Blue" which is pretty much useless because you can’t have a CSS class that has two words for its name. But how do you get the selected value, instead of the selected label?

One option would be to use the values as the labels, but if you did that you could end up with a bunch of users who are confused over what the labels stand for. It really would be much better to show the user “Dark blue” while allowing you to get the value “dkblue” instead.

To accomplish that, you just need to get the persisted value of the multiple choice field:

var bgcolor = item.Fields.Color.PersistedValue;
<div class="card-over @bgcolor">  

About the Author

April was building websites fan shrines in the late '90s, oblivious to the fact that making websites is a thing people do for work. She studied journalism in college but only liked memorizing AP style rules and making websites to show off her assignments. When she's not at work, she enjoys kendo (Japanese fencing), yoga, and cooking.

Load more comments
Thank you for the comment! Your comment must be approved first
website user
New code

Best SEO Company -10 SEO's