Copied to clipboard

Flag this post as spam?

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


  • Simeon Ostberg 123 posts 389 karma points
    Nov 10, 2017 @ 12:42
    Simeon Ostberg
    0

    Add colour picker to Global Settings

    Hey guys,

    Since our congress uses different colours every year, I would like to add an easy colour picker to the Global Settings page. Unfortunately it doesn't work as desired.

    What I did:

    • In the document type "Global Configuration Settings" I added a textfield called "sTCLogofarbe" to enter the HEX code of the colour.
    • In the PageLogo partial view I added the line

      string stcfarbe1 = configPage.sTCLogofarbe.IfNull(x => "").ToString();
      

    And then the plan was to replace the colour code in the CSS by @stcfarbe1, but I don't get so far. The page produces a runtime error, and the log says:

    System.Web.HttpCompileException (0x80004005): c:(...)\PageLogo.cshtml(9): error CS1061: 'Umbraco.Web.PublishedContentModels.ConfigGlobalSettings' does not contain a definition for 'sTCLogofarbe' and no extension method 'sTCLogofarbe' accepting a first argument of type 'Umbraco.Web.PublishedContentModels.ConfigGlobalSettings' could be found (are you missing a using directive or an assembly reference?)

    What can I do to make this work?

    Thanks a lot! Simeon

  • Sotiris Filippidis 286 posts 1501 karma points
    Nov 10, 2017 @ 12:48
    Sotiris Filippidis
    0

    By default this starter kit uses Models Builder in DLL mode. So in order to have strongly-typed properties on your front-end, you will need to regenerate models to include this new property, by going to Developer - Models Builder - Generate Models. Note that the first letter of your property will be capitalized in the strongly-typed model.

    An alternative is to use the good old "magic string" approach, like:

    string stcfarbe1 = configPage.GetPropertyValue<string>("sTCLogoFarbe").IfNull(x=>"");
    
  • Simeon Ostberg 123 posts 389 karma points
    Nov 10, 2017 @ 13:23
    Simeon Ostberg
    0

    Dear Sotiris,

    Thanks! How do I implement this in the CSS? If I use

    color: @stcfarbe1;
    

    to call the value, this is being ignored. The same with

    color: "@stcfarbe1";
    

    Sorry for my stupid questions...

    Best, Simeon

  • Sotiris Filippidis 286 posts 1501 karma points
    Nov 10, 2017 @ 13:26
    Sotiris Filippidis
    100

    I assume you have either inline CSS or a style element in your cshtml file - otherwise, if you're looking to use this variable on a .css file, it won't work.

  • Simeon Ostberg 123 posts 389 karma points
    Nov 10, 2017 @ 13:28
    Simeon Ostberg
    0

    I understand. Ok, then I have to think about it.

    Thanks a lot!

    Best, Simeon

Please Sign in or register to post replies

Write your reply to:

Draft