Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 1285 posts 3917 karma points c-trib
    Dec 10, 2022 @ 16:56
    Dan
    0

    Read value from app settings in custom class

    Hi,

    I have a Tag Helper for rendering responsive images in Umbraco 11. I'd like to be able to read the value for maximum image width and height, which I can see is set as 5000 by default in both the appsettings-schema.json and /umbraco/config/appsettings-schema.json files:

        "Resize": {
          "properties": {
            "MaxWidth": {
              "description": "Value for the maximum resize width",
              "type": "integer",
              "default": 5000
            },
            "MaxHeight": {
              "description": "Value for the maximum resize height",
              "type": "integer",
              "default": 5000
            }
          }
        }
    

    I've seen the documentation on how to read configuration data in code but I'm not sure what to do to be able to read the image size values as they're set in the appsettings-schema file rather than the appsettings file. Is it just a case of replicating that part of the json object so it's in the main appsettings.json file, from where it will be readable?

    (As a related question, out of curiosity, how would you override these values - would do you that in the appsettings-schema file or the appsettings file?)

    Thanks for any clarification on this!

  • Dan 1285 posts 3917 karma points c-trib
    Dec 10, 2022 @ 17:28
    Dan
    100

    Think I figured it out! 😅

    To override the values, it would be a case of modifying the appsettings.json file, like this:

    "Umbraco": {
        "CMS": {
            ...keep existing settings here but add the following...
            "Imaging": {
                "Resize": {
                    "MaxWidth": 6000,
                    "MaxHeight": 6000
                }
            },
        }
    

    Then to read those values in code, you'd follow the docs but instead of using GlobalSettings, use ImagingSettings.

Please Sign in or register to post replies

Write your reply to:

Draft