UmbracoDocs icon indicating copy to clipboard operation
UmbracoDocs copied to clipboard

Adding values programmatically through Views is bad practice

Open Migaroez opened this issue 1 year ago • 4 comments

What type of issue is it? (Choose one - delete the others)

Bad practice promotion

What article/section is this about?

(multinode-treepicker)

Describe the issue

We shouldn't be promoting back practices like injecting core services into templates as this can lead to people using the services for content fetching

We should also try to tell a story with a code example and make it as close to a good practice example as possible (no hard coded id's)

Migaroez avatar Oct 18 '23 12:10 Migaroez

I somewhat agree, but that is how every "how add values programmatically" is done. https://github.com/search?q=repo%3Aumbraco%2FUmbracoDocs%20programmatically&type=code

skttl avatar Oct 19 '23 06:10 skttl

Hi @Migaroez thank you for bringing this to our attention. In order to understand the issue better, can you elaborate more specifically on what you would like to change in the documentation and where (if you have a specific content part in mind)? 🙏

alina-tincas avatar Oct 19 '23 13:10 alina-tincas

@Migaroez @alina-tincas @skttl I agree that the way this is currently done is not the best example, and we should prevent it from being adopted. I believe it was chosen at some point because it's a simple way to demonstrate how values can be added from code. As @skttl also points out, this has been done in the same way for all property editors, so if any adjustments are made, it should actually be adapted for all property editors to maintain consistency.

One option could be to create examples, for instance, from an API Controller (perhaps there are better scenarios as well?). Of course, we can also add a note indicating that this should not be done from a view, but it was done to quickly and easily illustrate how values can be added from code.

erikjanwestendorp avatar Nov 09 '23 13:11 erikjanwestendorp

Hi there 👋

It looks like this discussion has gotten a bit stale over the past 6 months. I've been looking into the issue being discussed here and I agree that we shouldn't be promoting bad or not recommended practice in our documentation!

I also agree, that the samples we use in our documentation like this should ideally be telling a story, or at least use some sort of "real life" example. However, how we go about this is not super clear to me at the moment.

One of you suggest using the API controllers, which would also be my go-to if I had to rewrite the samples. But... these are deprecated and will be removed from Umbraco 15, right? At least, that is what we're saying in this article: https://docs.umbraco.com/umbraco-cms/reference/routing/umbraco-api-controllers - I might be wrong!

I will take this up internally here at Umbraco HQ after the summer holidays, in order to decide how we want to showcase creating content programmatically going forward.

Until then, I like the idea of adding a little note about how we're currently using the Views as a quick way to illustrate how values in content can be added/updated from code! So let's do that as a start💪

sofietoft avatar Jul 03 '24 08:07 sofietoft