This is a follow up to last year's great post by Dave Woestenborghs, where he goes through how you can control, hide or schedule a block's "published" state to empower your editors. He also went through how to render blocks in the backoffice using the partial views the site would use for the front end, reducing a developer's maintence and start up cost. You can find it in last year's posts - https://24days.in/umbraco-cms/2021/advanced-blocklist-editor/
Using this code as a base I have also added the ability to use ViewComponents directly for blocks, as well as previewing with them! This is great for those complex blocks where you want to manipulate or further hydrate the blocks data.
In case you havent used V9 or .NET Core lets talk ViewComponents. Coming from previous versions of Umbraco and dotnet I feel the best way of looking at them is as child actions (Html.Action()
), however they don't use model binding so you can easily pass anything to them. Although, with the ability to inject services into Razor views, the need for separation of simple logic or service calls might not be something you need to do as often, depending on your preferences.
Lets take a look at a ViewComponent for a frequently asked questions block.