You could use properties that are media pickers to pick folders from your content nodes rather than having to search through the entire media tree.
You could either have the user set those properties (i.e., pick the media folders), or you could use your code to automatically pick those folders, then have your code programmatically set the picker property so next time it doesn't have to scan the entire media tree.
You can get a node by its ID, set a property, then save it with the content service.
You can use GetPropertyValue on the current IPublishedContent to get the value of the media picker property (which, of course, you will have to add to the appropriate document types).
Is it possible to optimize this code that gets an image from the Media section?
I have the following code executing in the head section of my template. It works fine, but I was curious if it could be optimized?
You could use properties that are media pickers to pick folders from your content nodes rather than having to search through the entire media tree.
You could either have the user set those properties (i.e., pick the media folders), or you could use your code to automatically pick those folders, then have your code programmatically set the picker property so next time it doesn't have to scan the entire media tree.
Do you have sample code on how I would do that? Thanks
Look at the content service: https://our.umbraco.org/Documentation/Reference/Management/Services/ContentService
You can get a node by its ID, set a property, then save it with the content service.
You can use GetPropertyValue on the current IPublishedContent to get the value of the media picker property (which, of course, you will have to add to the appropriate document types).
is working on a reply...