December 21, 2023 Web Development

Identify Pages With a Specific 2sxc Content Item

Every now and then, you will run into an instance where you need to identify the pages where a particular piece of 2sxc content is being used.

Example Use Case:

We just built out a sweet testimonial component on our website. This component is built with a view that contains a list of testimonials we’d like to show on the page.

When we built our website, we used a few placeholder testimonials, which we planned to remove once we had real testimonials.

Now that we’ve built the site with dozens of pages, how can we quickly identify the pages where our two placeholder testimonials exist?

Start by Looking at Your Views:

Within the Views tab of the 2sxc admin interface, you will see a column for “Used”. This Used column indicates how many times this particular view is being used. You can click on the column quantity to see all pages where this view is used.

Clicking on the 'used' column will show you the specific pages where that view is being used.
The 2sxc admin panel, views tab can show you the number of times each view is used.

This shows us every page where this particular template is being used. Great, this is super helpful. It can help us eliminate a large number of pages that we need to check. But this template is a list, and with lists, we can reuse content types any number of times. We could see a specific testimonial on one, many, all, or none of these pages. How can we find the particular pages where a specific testimonial is visible?

Identifying Specific Content Pieces

I don’t believe 2sxc has a built-in way to show specific pages where specific content items are used, but we can run an SQL query to identify this. Here is what it looks like.

Before we can run our SQL queries, we first need to get the content item’s GUID. You can get this by hovering over and clicking the ID from the listing of “items” for this particular Content Type.

Viewing 2sxc Content Items from the 2sxc admin interface

Once you have the entry you are looking for, we can run a query to return the pages where this content type item has been identified:

SELECT
   ModuleSettings.ModuleID,
   VW_Modules.TabID
FROM ModuleSettings
LEFT JOIN VW_Modules ON ModuleSettings.ModuleID = VW_Modules.ModuleID
WHERE SettingValue IN (
   SELECT CONVERT(VARCHAR(36), EntityGUID)  -- Convert EntityGUID to string
   FROM ToSIC_EAV_Entities
   WHERE EntityGUID = '{{content_type_item_guid}}' OR
   JSON LIKE '%{{content_type_item_guid}}%'
);

We can use then use a URL like: https://{{your_website}}/default.aspx?tabid={{tabid}}, to load the identified pages. From here, we can review and update the content as needed.

Where is this helpful?

In most instances, using the View tab “Used” column to see which pages a particular view is being used can help quickly get you to the right place. This can fall short when you have a lot of content using a specific template.  A large site can reuse a template file several dozen times, and you’d need to review every page to search for that particular piece of content.

Removing a content-type item from the admin interface while it is still connected to a view is not usually advised because it can cause errors when 2sxc tries to render the page and it realizes that the content item no longer exists.

It’s also worth noting that from the “Data” view in 2sxc, we can see a “Times Used” column. This indicates how often a specific 2sxc Template View uses this data. This doesn’t tell us how many times the modules that use this are found on the website. If we copy a module to 10 pages, this “Times Used” column will only show one instance. The Times Used count indicates how many 2sxc views are using this item.

Image Credit: Adobe Firefly