Our.Umbraco.HiddenValue

  • 20/01/2022
  • Packages
  • Umbraco 9, Nugets, Backoffice

Welcome back to my garage fellow Umbracians! Today I am here because I wanna share my second package with you:

Our.Umbraco.HiddenValue



When do I need this?

How often you had the problem that you have some path or static value within your code that may change at some point.

Normally you have 2 choices at that point:

● Create a property in Umbraco so you can change the value at any point, probably the best solution, however you always have to fear that an editor accidentally changes the value

● Create a variable within your code. Thats fine for the most parts but you will get trouble when you need to change the value as you will need to deploy your changes to the system(s)

Wouldn't it be great to have a field where you as an developer can save some value without the fear of it beeing changed by an editor who doesn't know what he is doing?

Thats where my package come in!

What does it?

This package allows you to create properties with a value within your content type.

The property will also not beeing shown within the Content, so you don't need to fear any editor changing your value!

How to use it?

Go to the content type you want to have the HiddenValue on. Create a new property and choose the HiddenValue type.

Select The Hidden Value Field

Next enter your value and then save it.

Editor Settings

Finished. All you content based on that content type will now have your field with the entered value on it!

You can access the value just like any other field by its alias or using the ModulsBuilder.

The value returned by it will always be a simple string.

How does it work in the background?

There are basically three notification handlers doing all the work:

1. ContentSavingHandler: After saving a new content item is beeing saved it will look if a property is based on the HiddenValue property type, if it finds one it will take the value from the datatype configuration and saves it to the field.

2. ContentTypeSavedHandler: When you save a content type with an HiddenValue property on it, it will look if any content is already based on it, if so the content is updated witth the new value of from the HiddenValue field.

3. ContentSendingHandler: When a content is loaded in the Content section it will check if a property is based on the HiddenValue property type - if it finds one the field will get removed and the editor will not see it.

How do I get it?

Nuget: https://www.nuget.org/packages/Our.Umbraco.HiddenValue/9.0.0


dotnet add package Our.Umbraco.HiddenValue --version 9.0.0
                                

You can also find the source code on my github https://github.com/ReiterM2000/Our.HiddenValue

The repository is also open for contribution, if you think you can improve it feel free to do so!

If you find a bug or have a request you can always hit me up or create an issue at the github repo

I hope you will find a use for my package and enjoy it as much as I do!

If you have any questions, feel free to contact me