Creating Individual Search Indexes for Multiple Sitefinity Blogs

Sitefinity provides the ability to index all of your content so that it is easily searchable by your visitors. You can also partition the contents of the search into separate indexes based on the different content types, such as News, Blogs, Events, etc.

However, what if you have multiple blogs but want your visitors to be able to limit their search to a single specific blog? That’s the focus of today’s post.

Read more at the Falafel Software Blogs: Creating Individual Search Indexes for Multiple Sitefinity Blogs

Querying the List of Sitefinity Dynamic Modules and Types

The Code Reference of the Sitefinity Module Builder makes it simple to get started building custom widgets and components to interact with your Dynamic Modules. However, the generated code is specific to each module and type, requiring that you pass in the full type as a string, resolving the type at runtime.

But what if you need to write generic code that could be used for multiple dynamic modules, where you won’t necessarily know in advance what the types are?

The answer is the ModuleBuilderManager, which exposes methods for retrieving both modules and their associated types. Let’s take a closer look at what you need to do to query modules and types..

For this example I’ve created a few sample dynamic modules, leaving one in a disabled state so you can see how the results differ.

Read more at the Falafel Software Blogs: Querying the List of Sitefinity Dynamic Modules and Types

Selecting Dynamic Content in Native Sitefinity Modules with Custom Fields

The Sitefinity Module builder allows you to create custom types on the fly for use as custom modules.

In the 5.0 release back in February, a two new field types were added to the module builder: Guid and Array of Guids. These allow you to “link” content items using their Id properties, adding support of one-to-many and many-to-many relationships between your content.

Radoslav posted a helpful sample of a custom dynamic content selector field control that allows you to select content for these relationships. While this sample is thorough, it is a lot of custom code to work with if you simply want to make a basic association.

Such a situation occurs with the recently released Sitefinity MVC Store sample project. In this project, there are two content types Artist and Genre that are referenced in a one-to-many relationship to the content type Album. Instead of implementing the full selector above, a simpler control was created by inheriting from the existing ChoiceField control.

This field already contains a lot of the functionality required, since it was designed to present a list of options to the user, in many forms. In this case, the field is defaulted to a dropdown list:

sitefinity-custom-module-content-selector-field-3-

In this example, the name of the field (Artist and Genre exactly match the name of the Content Type being associated. This eliminates the need to create a separate field for each content type, and it can even be reused in other content modules.

Here is the full code for this custom field control, showing how this was achieved.


View Code Sample on Gist

Keeping the Default Behavior

Notice that not only does this control inherit from ChoiceField but the ScriptDescriptorType and ResourcesAssemblyInfo overrides also force this control to reuse the base behavior of that field. The reason for this is that by doing so, the control will reuse the native JavaScript file for the designer, so that it isn’t necessary rewrite a entirely new script from scratch just to accommodate our custom type. Instead, the default one for ChoiceField is compatible since this control inherits directly from it.

Defining the Desired Behavior

Also, you can see that the RenderChoicesAs property forces a list. This could be modified if you a different input type is required. However, using a custom field does not present the option to set this on the website when the field is added, so it is explicitly set here.

Populating the Choice Collection

Finally, the Configure method takes care of actually loading the choices and presenting them to the user. While you can certainly hard-code your custom module and content types into the control, the FieldDefinition that is passed to this method includes a lot of information that can be used to extract the data needed to load the content items.

The ControlDefinitionName contains the type of the current content type using dot notation (Example: Telerik.Sitefinity.DynamicTypes.Model.MusicStore.Album), so removing the last element results in the parent module type.

NOTE: This selector does not account for nested or child types, and should be modified if you are using such a content type.

The name of the field is stored in the FieldName property, and appending them together results in the full name of the dynamic content type.

This name can then be used to initialize the Content Type required by the Dynamic Module Manager to retrieve content items of that type. From there a simple use of the Sitefinity API retrieves the published items and binds them to the Choices collection so they can be shown in the dropdown list.

sitefinity-custom-module-content-field-dropdown-4-

Retrieving Associated Items Using the API

Once your content items are added with these associations using the new custom field, you can easily retrieve them back using the API. This is demonstrated in the Browse method of the StoreController.cs class:
View Code Sample on Gist

Which reveals the albums which match the selected Genre:

sitefinity-custom-module-related-items-3-

Check if a Sitefinity Module is Installed or Disabled

When working with the Sitefinity API and its various Content Managers, you need to make sure and consider the fact that after version 5.1, users have the ability to disable modules. Attempting to access the content manager of a disabled module will result in an exception.

Sitefinity Lightning CTP

With all the new features in the latest 5.2 release of Sitefinity, it’s easy to almost miss Sitefinity Lightning. And after finally taking the time to play with it today, you surely do not want to miss it!

Mapping Sitefinity Templates from the SDK

There are several different ways to map Sitefinity widgets to external templates, including globally using the ViewMap. You can also use the built-in Sitefinity Widget Template editor and even Sitefinity Thunder to modify templates and copy them to external files.

However, did you know that a copy of every single widget template is included in the Sitefinity SDK?

When you install the SDK, a zip file named WidgetTemplates.zip, which contains a copy of every usable Sitefinity template is copied to your machine.

Product Maximum and Minimums in Sitefinity Part 2: Shopping Cart

We previously looked at how you can enforce minimum and maximum product quantities on the Sitefinity product details page. However, users can still override the quantities in the shopping cart, defeating the restrictions.

Fortunately, the shopping cart template also includes a validation control for each item. By mapping this control to an external User Control template as well, we can tap into this validator with custom code just as we did before.