Filter dynamic content items by URL
With the support of hierarchical dynamic modules, Sitefinity CMS provides ability to filter the dynamic content items by their parents. The following tutorial describes how to filter dynamic content items by their parent via the URL.
The following tutorial creates the relationship between Countries, Cities and Hotels. For more information about creating the module and its content types, see Create Travelling agency site with hierarchical types.
Once you activate the dynamic module, a corresponding section is created in Sitefinity CMS toolbox with both Standard and MVC widgets reflecting the names of the content types.
EXAMPLE: For a module with name Travelling Agency, section with name Travelling Agency is created. For Countries dynamic content type, two widgets are automatically added to the toolbox section - Countries and Countries MVC.
To filter the dynamic content items by their parents, perform the following:
- Create new page with name Cities and drop the Cities MVC widget on the page.
- Click the Edit button to open the widget designer.
- In the Content tab select From currently open country radio button and click Save.
As a result the widget designer informs you that only Cities from the currently open Country will be displayed:
For more information, see Dynamic items selector.
- Save your changes, publish the page, and open it on the frontend.
The page displays an empty list.
- Tho choose whether you want to display the whole list of items when no country is specified in the URL, in the widget designer, click Advanced » Model.
In ShowListViewOnEmpyParentFilter, enter true or false. In this tutorial, leave the default value, which is false.
- To filter the cities by country, add a name of a country in the URL.
For example, http://domain:xxx/cities/bulgaria
A list of all the cities in Bulgaria appears.
If you click an item title, by default you are redirected to the details view of the item.
- To choose whether to open the detail view whan an item is clicked, in the widget designer, click Advanced » Model.
In In ListMode, enter true or false. True means that the detailed mode will not be opened.
In this tutorial, leave the default value, which is false.
NOTE: You can also display a list of dynamic content items and highlight the selected one. For more information, see Highlight filtered items.