Copied to clipboard

Flag this post as spam?

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


  • Gayathri 41 posts 151 karma points
    6 days ago
    Gayathri
    0

    Prevent css repetition in each content type

    Hi all,

    Currently, for every content type, css is embedded into the content type itself. Hence, css related to content type will only load when the content type is added into the page.

    However, if you add more than one of the same content type in a page, it will load the css again and again.

    So , this needs to be prevented.

  • Claushingebjerg 844 posts 2219 karma points
    6 days ago
    Claushingebjerg
    0

    Could you post screen dumps or code examples? As far as im aware no css is embedded in templates or partials per default...

    Or are you talking about some kind of backend grid renderer...?

  • Gayathri 41 posts 151 karma points
    1 day ago
    Gayathri
    0

    Hi , Please find i have custom content type called Quicklinks , i have page where this content type used twice so the css repeating twice , How to avoid this ?

    enter image description here

  • Jonathan Distenfeld 95 posts 531 karma points
    1 day ago
    Jonathan Distenfeld
    0

    Hi,

    to give you an idea: You could write a method to avoid duplicate css. (Following is untested)

        private Dictionary<string, MvcHtmlString> stylesheetsLoaded = new Dictionary<string, MvcHtmlString>();
        public IHtmlString EnsureStyleSheet(string url)
        {
            MvcHtmlString result = MvcHtmlString.Empty;
            if (!stylesheetsLoaded.ContainsKey(url))
            {
                result = MvcHtmlString.Create($"<link rel=\"styleheet\" href=\"{url}\" />");
                stylesheetsLoaded.Add(url, result);
            }
            return result;
        }
    

    ~ Jonathan

  • Gayathri 41 posts 151 karma points
    1 day ago
    Gayathri
    0

    Hi Jonathan,

    Thank you for the reply :)

    This is my below the css and Js , these two items is repeating , how i can approach with the above one ?

    enter image description here

  • Jonathan Distenfeld 95 posts 531 karma points
    1 day ago
    Jonathan Distenfeld
    0

    Hi,

    You can call it like this:

    @EnsureStyleSheet("~App_Plugins/QuickLinks/Css/QuickLinks.css")
    

    For javascript-files you can do the same.

    You have to make sure that you have a single instance of the class containing the methods. Otherwise it won't work and the result will be the same.

    ~ Jonathan

Please Sign in or register to post replies

Write your reply to:

Draft