Microsoft 365 and SharePoint Online Cookbook
上QQ阅读APP看书,第一时间看更新

Adding a web part

Web parts are the smallest building blocks of a page. Each web part is a self-contained widget that lets you add text, images, files, videos, and other dynamically generated content to your page. This content can exist within your Microsoft 365 environment or can even exist externally.

In this example, we will add a news web part to our recently created page. This news web part will show a summary of all the news items within the current SharePoint site or from other SharePoint sites within your tenant.

Getting ready

You will need to have one or more of the following permission levels in your site to edit pages and add web parts to them: Contribute,Edit,Design, or Full Control.

How to do it...

To add a web part to a page, browse to the page you wish to add a web part to and follow these steps:

Click the Edit link from the page editing bar in the top-right corner of the page that you'd like to edit.

Click the + symbol at the bottom of the title area to reveal a list of web parts that you can add to your page.

Select a web part you would like to add. In this case, we will add the News web part, which aggregates news from your site, as shown in the following screenshot:

Click Editweb part(the pencil icon) to the left of the web part to optionally edit properties for the web part:

The properties you see will vary, depending on the type of web part that you are editing. For the News web part, you can select the source of news, its layout within the section, any filters you'd like to apply to the news, and how you'd like to organize the news.

You can then either save your changes as a draft or Republish the modified version of your page so that your changes are visible to other users.

That's it! You just learned how to add a web part to a page in SharePoint.

How it works...

When you edita page, its status changes to Draft as an indicator. Other users will continue to see the previously published version of the page, and the changes that you make to the page aren't visible to others unless you publish it again. It's only when you Republish the page that users will see the changes that you made to it.

A page in SharePoint can have multiple horizontal sections.Each section, in turn, can be subdivided into one or more vertical subsections or columns. You can then add web parts to the appropriate columns in these sections. You can add a section by clicking the + sign toward the left of your page:

SharePoint offers a variety of web parts that you can add to your page:

You can add web parts that let you enter text or wiki-like markdown on your page.

There's also a web part that, given an address, shows you the current weather information on your page.

There are also web parts for embedding images, documents, or content from secure (HTTPS only) third-party websites (such as YouTube) on your page.

You can show commonly used links on your page using the Quick links web part.

You can also show content from existing lists or libraries on your site using the corresponding list or document library web parts.

Your organization can develop custom web parts using one of the modern SharePoint development frameworks, such as the SharePoint Framework, which will be discussed in greater detail in Chapter 18, Custom Development - SharePoint Framework.

You also download a variety of third-party apps and web parts from the SharePoint store. We will discuss this in more detail in the Adding an app recipe, later in this chapter.

This is just a limited subset from the list of all the web parts that SharePoint has to offer. There are a ton of other web parts that enable interesting capabilities, which we encourage you to explore. You can view the complete list of web parts and an overview via this Microsoft support article: https://m365book.page.link/WebParts-List.

Remember that each web part comes with a set of properties that you can use to somewhat customize yours and your customers' experience.

There's more...

In this section, we will look at the concept of audience targeting, which lets you provide relevant content to users based on their profile attributes, such as their department or role, to name a couple.

Audience targeting

Audience targeting in SharePoint enables you to serve up relevant content to your users. It does this by allowing you to selectively restrict access to the following content to a targeted set of users:

Navigation links: This enables you to show certain links to particular groups. For example, you could potentially set a target audience on the HR menu link, from the top navigation menu, so that it only shows up for members of the HR department.

Pages and news: This enables you to target certain pages and news posts at certain groups. For example, you could set a target audience for a marketing news page so that it only shows for the members of the Marketing department.

Various web parts: Turning this filter on for the News and Highlighted content web parts enables these web parts to respect the target audience values that have been defined for the published news posts or various SharePoint list or library items.

Please note that audience targeting, in a sense, employees security by obscurity to only show relevant content (or rather hide irrelevant content) to the targeted users. This means that it does not change the underlying permissions of the underlying content but merely hides it from being shown up in the UI for users who are not part of the groups that the content is targeted at. For example, even if you set the audience for the HR site navigation link so that the link is only visible to HR department users, users that are not part of the HR department can still directly browse to the HR department site if they know the URL.

Using audience targeting is a great way to create a personalized experience for the users of your site. For example, you could have the same set of web parts on your site's home page and yet show different content to various users, depending on the departments or teams that they belong to.

The following Microsoft support articles provide a deep dive into the various concepts and how-tos of audience targeting:

Overview of audience targeting in modern SharePoint sites: https://m365book.page.link/Audience-Targeting-Overview

Target navigation, news, and files to specific audiences: https://m365book.page.link/Audience-Targeting-Uses