Create the City page
This page displays detailed information for a specific city. Hotels and restaurant suggestions are listed as well. In addition, it displays information about other places in the country of the current city
Display the detail information about a city
You can display detailed information about a city by dropping the Cities widget on the page and configuring it to display only city details. In order to do that, select the One particular city only... option and do not select a specific city. This way, the cities widget displays only details view of the currently navigated in URL city. For example, ~/city/united-states-of-america/new-york. You also set the Details item template of the cities widget to My vacation - Full city content template.
The following screenshot shows the display of Cities widget:
Use the following markup for My vacation - Full city content template:
- To display the name of the country where the city is locate, you can use the auto generated ParentItem property. For each item of child type, in dynamic module hierarchy, Sitefinity CMS generates system property ParentItem that can be used in the templates for retrieving information about the parent item.
In this case, if you want to display the name of the country, the current city is located in, add <%# Eval("ParentItem.Name") %> statement to the city details template.
For more information, see For developers: Property descriptor.
- Show links to other pages with contextual information about the current city. If you want to navigate to page ~/hotels and want to display contextual information about the current city, yet displaying all hotels in it, you need to generate a link like ~/hotels/united-states-of-america/new-york. Using the locations service in Sitefinity CMS, you can get a link to all pages that display information about specific type, in this case - City. Using the DynamicContentExtensions GetLocationAtIndex method, you can get URL at a specific location index – <a href="<%# ((DynamicContent)Container.DataItem).GetLocationAtIndex(2) %>" class="pill" >Hotels</a>
In a similar manner, you can get the link to the ~/restaurants page and display all restaurants for current country.
NOTE: Hotels and Restaurants pages must contain Hotels and Restaurants widgets that are configured to display items from currently opened City.
Display the top hotels in a city
Hotels are direct children of the currently opened in the URL item (city) and you can display them by dropping the Hotels widget on the page, and configuring it to display hotels From the currently open city. In addition, you need to set details page for the hotels to be the Hotel page. As list item template, select My vacation - List of hotels - Thumbnail And All hotels Link.
The following screenshot shows the display of Hotels widget:
Use the following markup for List of hotels - Thumbnail And All hotels Link template:
Display the top restaurants in a city
Restaurants are direct children of a City. This means that you can apply the same configuration as for the Hotels widget above. For displaying restaurants list, you use the My vacation - List of restaurants - Thumbnail and All restaurants Link template.
The following screenshot shows the display of Restaurants widget:
Use the following markup for My vacation - List of restaurants - Thumbnail and All restaurants Link template:
Show additional interesting places in the country of the city
When you are in a specific city, you may want to display additional information about the country that may be interesting for the users. Displaying information about the current country of the displayed city means displaying information about the parent item – Country.
To show information about the cities and festivals in a country you can drop the Countries widget, and configure it in the following way:
- Select the One particular country only... option and do not select specific country.
This sets the mode of the widget to Details.
- In Single item settings, set My Vacation - More in Country (List of cities and festivals) template.
- Enable the countries widget to resolve a country item when the page URL is similar to ~/city/united-states-of-america/new-york.
To do that, go to Advanced settings and set ShowDetailsViewOnChildDetailsView property to true.
The following screenshot shows the display of Countries widget:
Configuring the countries widget in this way, gives you the ability to easily display information about it in the widget template. For example, showing cities and festivals requires only two Eval methods and two repeaters.
Use the following markup for My Vacation - More in Country (List of cities and festivals) template:
To display all cities from a country, you can use the auto generated property Cities to access all child items.
When child type is added to the module structure, Sitefinity CMS generates automatically property descriptors for each child type and enables you to get all child items an Eval statement.
You can display all Festivals in the same way.