How To Add Template In Web Part In SharePoint 2013

Adding a template to a web part in SharePoint 2013 can enhance the display and layout of your content. To achieve this, you need to understand display templates and how they control the appearance of your content in the Content Search Web Part (CSWP).

There are two types of display templates: control display templates and item display templates. Control display templates define the overall layout, while item display templates define the display for each item in the search results.

To add the display templates, you can upload the necessary HTML and JavaScript files to the Master Page Gallery. Specifically, navigate to the Display Templates > Content Web Parts folder. This will ensure that the templates are available for use.

Once you have uploaded the templates, you can apply them to the CSWP by editing the web part. From there, you can select the appropriate templates from the Control and Item menus to define how your content is displayed.

Once the templates are applied, don’t forget to save the page. Only by doing so will you be able to see the updated display and appreciate the enhanced layout of your content.

Understanding Display Templates in SharePoint 2013

Display templates play a crucial role in defining the layout and display of content in a Content Search Web Part (CSWP) in SharePoint 2013. These templates are used to control how the content is presented, ensuring consistency and visual appeal throughout the site.

There are two types of display templates: control display templates and item display templates. Control display templates define the overall layout of the CSWP, including the positioning and styling of elements such as headers, footers, and navigation menus. Item display templates, on the other hand, define how each individual item in the search results is displayed, including the fields and metadata that are shown.

To add display templates to SharePoint 2013, you can upload the necessary HTML and JavaScript files to the Master Page Gallery. Specifically, you need to navigate to the Display Templates folder, which is located within the Content Web Parts section. Once the files are uploaded, they can be applied to the CSWP.

Applying the display templates is a straightforward process. First, you need to edit the web part settings of the CSWP. Within the settings, you will find options to select the control display template from the Control Menu, and the item display template from the Item Menu. Once the appropriate templates are selected, you can save the page to see the updated display.

Display Template Description
Control Display Template Defines the overall layout of the CSWP, including headers, footers, and navigation menus
Item Display Template Defines the display for each individual item in the search results, including fields and metadata

Summary:

In SharePoint 2013, display templates are essential for controlling the appearance of content in a CSWP. By adding control and item display templates, you can customize the layout and display of search results, ensuring a consistent and visually appealing user experience. Take advantage of the Master Page Gallery to upload the necessary HTML and JavaScript files, and then apply the templates to the CSWP by editing the web part settings. With display templates, you can enhance the presentation of content in SharePoint 2013 and deliver a more engaging and user-friendly website.

Adding Display Templates to SharePoint 2013

To add display templates to SharePoint 2013, you will need to upload HTML and JavaScript files to the designated folder in the Master Page Gallery and apply them to the desired Content Search Web Part. Display templates are used to control how content is displayed in the web part, allowing you to customize the layout and appearance of search results.

Start by accessing the Master Page Gallery in SharePoint 2013. This can be done by navigating to the site collection and selecting “Site Settings” from the gear icon menu. Under the “Web Designer Galleries” section, click on “Master pages and page layouts” to access the gallery.

Within the Master Page Gallery, locate the “Display Templates” folder and then select “Content Web Parts”. This folder is where you will upload your HTML and JavaScript files. To upload the files, click on the “Files” tab in the ribbon and choose “Upload Document”. Select your HTML and JavaScript files from your computer and click “Ok” to upload them to the gallery.

Once the files are uploaded, you can apply the display templates to the Content Search Web Part. Navigate to the page where the web part is located. Edit the page and select the Content Search Web Part. In the web part properties pane, expand the “Display Templates” section. From here, you can choose the appropriate control and item templates from the dropdown menus to define the overall layout and display of the search results.

Control Display Template Item Display Template
Defines the overall layout of the search results Defines the display for each item in the search results

After selecting the templates, save the page to see the updated display. The Content Search Web Part will now use the specified display templates to present the search results according to your customizations. By leveraging display templates, you can create a more visually appealing and relevant user experience in SharePoint 2013.

Applying Display Templates to the Content Search Web Part

Once you have uploaded the display templates, you can easily apply them to the Content Search Web Part by following these simple steps. First, edit the web part by selecting the “Edit Web Part” option from the control menu. This will open the web part settings.

In the web part settings, navigate to the “Display Templates” section. Here, you can select the appropriate templates from the Control and Item menus. The Control menu allows you to choose the control display template, which defines the overall layout of the search results. The Item menu, on the other hand, lets you select the item display template, which determines how each item in the search results is displayed.

After selecting the desired templates, click “Save” to apply the changes. This will update the display of the Content Search Web Part on the page. You can now view the results with the new display templates in place.

Meet the Author

Abdul Rahim has been working in Information Technology for over two decades. Learn how Abdul got his start as a Tech Blogger , and why he decided to start this Software blog. If you want to send Abdul a quick message, then visit his contact page here.