3
votes

I have created the Project using DNN. I have written my CSS code in say "main.css". Firstly, I have created the HTML of the Project and then I have integrated it with DNN.

Now, the DNN default.css, skin.css and portal.css is overriding the main.css. I need a way to that when I am logging in through admin then only "default.css, skin.css and portal.css" this CSS should get applied. Otherwise for Normal users it should not get applied..

Simple flow of css to add

Admin User - default.css, skin.css , portal.css and main.css

Normal User - main.css

Hope My question is understandable..

5

5 Answers

3
votes

disable or remove the default.css, skin.css and portal.css in DNN for normal Users

For DNN 7 :- Disable/Remove unwanted (default) css files to be loaded in DotNetNuke (DNN)

For DNN 8:-

<script type="text/javascript">
    $(document).ready(function () {
        if ($('#ControlBar_ControlPanel').length == 0) {
            $('head link[href*="/Resources/Shared/stylesheets/dnndefault/7.0.0/default.css"]').remove();
            $('head link[href*="/Resources/Shared/stylesheets/dnndefault/8.0.0/default.css"]').remove();
        }
    });
</script>
1
votes

Your best bet will probably be to use the StyleHelper SkinObject https://stylehelper.codeplex.com/

Or some modified version of that.

1
votes

<%@ Register TagPrefix="dnn" Namespace="DotNetNuke.Web.Client.ClientResourceManagement" Assembly="DotNetNuke.Web.Client" %>

<dnn:DnnCssExclude runat="server" Name="dnndefault" />

Put those above in the page template file, like home.ascx, index.ascx. It will remove default.css, can I ask you why are you going to remove it? it will cause an issue when you are trying to add a new module and you probably are not able to drag the module in the admin mode (I'm using DNN9.8)

0
votes

Default.aspx: at first line replace CodeBehind with CodeFile attribute.

in Default.aspx.cs in OnPreRender method add at bottom:

var loader = Page.FindControl("ClientResourceIncludes");
var toRemove = new List<ClientDependencyInclude>();
foreach (ClientDependencyInclude ctl in loader.Controls)
{        
    if (ctl.FilePath.Contains("/Resources/Search/SearchSkinObjectPreview.css")
       || ctl.FilePath.Contains("/Portals/_default/admin.css"))
       toRemove.Add(ctl);
    }
}    

foreach (var ctl in toRemove)
    loader.Controls.Remove(ctl);

all error checking skipped for clarity

-2
votes

You could use php to add link tags for admin, something like

<?php
if ($_SESSION["pseudo"] = "admin") {
?>
<link rel="stylesheet" type="text/css" href="default.css">
<link rel="stylesheet" type="text/css" href="skin.css">
<link rel="stylesheet" type="text/css" href="portal.css">
<?php
}
?>
<link rel="stylesheet" type="text/css" href="main.css">