- Sitecore Cookbook for Developers
- Yogesh Patel
- 433字
- 2021-07-16 11:15:03
Creating a gutter to show unpublished items
In the Content Editor, the left margin of the content tree is known as gutter. This area contains icons that can be used to display the status or type of the corresponding item and icons can be toggled on or off.
Let's create a custom gutter icon to identify unpublished items so that we will be able to know the publishing status of all expanded items very easily.
How to do it…
- In the
SitecoreCookbook
project, create aPublishGutter
class in theGutters
folder, and inherit it from theSitecore.Shell.Applications.ContentEditor.Gutters.GutterRenderer
class. - Add
enum PublishStatus
to show the publishing status as follows:enum PublishStatus { Published, NeverPublished, Modified }
- Add the
CheckPublishStatus()
method to know the publishing status of the current item:private PublishStatus CheckPublishStatus(Item currentItem) { Database webDB = Factory.GetDatabase("web"); Item webItem = webDB.GetItem(currentItem.ID); if (webItem == null) return PublishStatus.NeverPublished; if (currentItem["__Revision"] != webItem["__Revision"]) return PublishStatus.Modified; return PublishStatus.Published; }
- Override the
GutterIconDescriptor()
method to decide which gutter icon to show for the current item, which we will decide based on the publishing status:protected override GutterIconDescriptor GetIconDescriptor(Item item) { PublishStatus publishStatus = CheckPublishStatus(item); if (publishStatus != PublishStatus.Published) { GutterIconDescriptor desc = new GutterIconDescriptor(); if (publishStatus == PublishStatus.NeverPublished) { desc.Icon = "Core2/32x32/flag_red_h.png"; desc.Tooltip = "Item never published!"; } else { desc.Icon = "Core2/32x32/flag_yellow.png"; desc.Tooltip = "Item published but modified!"; } desc.Click = string.Format("item:load(id={0})", item.ID); return desc; } return null; }
- Open the Sitecore desktop and switch the database to
core
. Open the Content Editor and select the/sitecore/Content/Applications/Content Editor/Gutters
item. Under it, create aPublishing Status
item using the/Sitecore Client/Content editor/Gutter Renderer
template. - In the Field Editor pane, enter field values, as shown in the following image:
- Now, open the Content Editor with the
master
database. Right-clicking on the left-hand side of the content tree will open a pop-up menu of all gutters, as shown on the left-hand side of the following image. Clicking on the Publishing Status gutter will show gutters with red and yellow flags, as shown on the right-hand side of the the following image: - The preceding image shows that the Content item has been published but has some modifications to it (marked with a yellow flag). The News item was never published (marked with a red flag) and all other items have been published (no flag).
推薦閱讀
- ClickHouse性能之巔:從架構(gòu)設(shè)計(jì)解讀性能之謎
- 案例式C語(yǔ)言程序設(shè)計(jì)
- Rust實(shí)戰(zhàn)
- Java Web基礎(chǔ)與實(shí)例教程(第2版·微課版)
- Python爬蟲(chóng)開(kāi)發(fā):從入門(mén)到實(shí)戰(zhàn)(微課版)
- R語(yǔ)言游戲數(shù)據(jù)分析與挖掘
- Python編程完全入門(mén)教程
- BeagleBone Black Cookbook
- 算法設(shè)計(jì)與分析:基于C++編程語(yǔ)言的描述
- Spring Boot從入門(mén)到實(shí)戰(zhàn)
- 循序漸進(jìn)Vue.js 3前端開(kāi)發(fā)實(shí)戰(zhàn)
- 編寫(xiě)高質(zhì)量代碼之Java(套裝共2冊(cè))
- Learning Java by Building Android Games
- R for Data Science Cookbook
- React Router Quick Start Guide