{"id":2060,"date":"2017-05-10T08:15:28","date_gmt":"2017-05-10T08:15:28","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=2060"},"modified":"2018-10-10T17:15:57","modified_gmt":"2018-10-10T17:15:57","slug":"primeng-theming","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=2060","title":{"rendered":"PrimeNG Theming"},"content":{"rendered":"<h4>Update 12\/5\/2017<\/h4>\n<p>Note that there are issues when trying to use the standard themes loaded by the PrimeNG installation, which reside under node_modules. Basically, the traditional use of the link tag did not work even though the style files were present.&#160; This appears to be an issue relating to how the application is packaged and served.<\/p>\n<p>See <a href=\"http:\/\/salientsoft.co.uk\/?p=2069\">this post<\/a> in the \u2018Styles configuration issue\u2019 near the end for details and resolution on this problem.<\/p>\n<h4>&#160;<\/h4>\n<h4>Original Post<\/h4>\n<p>This is handled in much the same way as it was in JSF \u2013 a directory for each theme holds its scss and css files.<\/p>\n<p>Normally these are bundled in as part of an npm installation of primeng, so the themes end up under <em>node_modules\\primeng\\resources\\themes,<\/em> but this may differ if you have your own custom themes.<\/p>\n<p>The PrimeNG showcase for example does not use an npm install of primeng, but declares its own primeng package as it contains everything. It therefore puts the themes under <em>resource\\themes. <\/em>See <a href=\"http:\/\/salientsoft.co.uk\/?p=2051\">this post<\/a> for issues with this re getting the showcase to work locally.<\/p>\n<p>The showcase is instructive as a simple example of how to switch themes \u2013 at present there does not appear to be a theme switcher\/manager component available.<\/p>\n<p>The basic style link tag which picks up a theme is in index.html:-<\/p>\n<blockquote>\n<pre>&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;resources\/themes\/omega\/theme.css&quot;&gt;<\/pre>\n<\/blockquote>\n<p>The following javascript function modifies this dynamically as themes are selected:-<\/p>\n<blockquote>\n<pre>var DemoApp = {<br \/><br \/>    changeTheme: function(event, element) {<br \/>        var theme = $(element).data(&quot;theme&quot;),<br \/>        themeLink = $('link[href$=&quot;theme.css&quot;]'),<br \/>        newThemeURL =  'resources\/themes\/' + theme + '\/theme.css';<br \/><br \/>        themeLink.attr('href', newThemeURL);<br \/>        event.preventDefault();<br \/>    }  <br \/>};<\/pre>\n<\/blockquote>\n<p>The following markup is used for theme selection, based on a hard coded list of the themes available:-<\/p>\n<blockquote>\n<pre>&lt;span class=&quot;topbar-link&quot; id=&quot;themeSwitcher&quot;<br \/>      (mouseenter)=&quot;themesVisible = true&quot; (mouseleave)=&quot;themesVisible = false&quot;&gt;<br \/>    &lt;img src=&quot;showcase\/resources\/images\/themeswitcher.svg&quot; \/&gt;<br \/>    &lt;span&gt;Themes&lt;\/span&gt;<br \/>    &lt;div id=&quot;GlobalThemeSwitcher&quot; [style.display]=&quot;themesVisible ? 'block' : 'none'&quot; style=&quot;margin-top:10px&quot;&gt;<br \/>        &lt;span&gt;Premium Templates&lt;\/span&gt;<br \/>        &lt;a href=&quot;http:\/\/www.primefaces.org\/layouts\/ultima-ng&quot;&gt;<br \/>            &lt;img src=&quot;showcase\/resources\/images\/themeswitcher-ultima.png&quot; alt=&quot;Ultima Template&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Ultima&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;http:\/\/www.primefaces.org\/layouts\/barcelona-ng&quot;&gt;<br \/>            &lt;img src=&quot;showcase\/resources\/images\/themeswitcher-barcelona.png&quot; alt=&quot;Barcelona Template&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Barcelona&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;http:\/\/www.primefaces.org\/layouts\/morpheus-ng&quot;&gt;<br \/>            &lt;img src=&quot;showcase\/resources\/images\/themeswitcher-morpheus.png&quot; alt=&quot;Morpheus Template&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Morpheus&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;http:\/\/www.primefaces.org\/layouts\/atlantis-ng&quot;&gt;<br \/>            &lt;img src=&quot;showcase\/resources\/images\/themeswitcher-atlantis.png&quot; alt=&quot;Atlantis Template&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Atlantis&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;http:\/\/www.primefaces.org\/layouts\/poseidon-ng&quot;&gt;<br \/>            &lt;img src=&quot;showcase\/resources\/images\/themeswitcher-poseidon.png&quot; alt=&quot;Poseidon Template&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Poseidon&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;http:\/\/www.primefaces.org\/layouts\/omega-ng&quot;&gt;<br \/>            &lt;img src=&quot;showcase\/resources\/images\/themeswitcher-omega.png&quot; alt=&quot;Omega Template&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Omega&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;span&gt;Free Themes&lt;\/span&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;omega&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Omega&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;bootstrap&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Bootstrap&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;cupertino&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Cupertino&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;cruze&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Cruze&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;darkness&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Darkness&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;flick&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Flick&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;home&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Home&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;kasper&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Kasper&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;lightness&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Lightness&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;ludvig&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Ludvig&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;pepper-grinder&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Pepper-Grinder&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;redmond&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Redmond&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;rocket&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Rocket&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;south-street&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;South-Street&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;start&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Start&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;trontastic&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Trontastic&lt;\/span&gt;&lt;\/a&gt;<br \/>        &lt;a href=&quot;#&quot; data-theme=&quot;voclain&quot; onclick=&quot;DemoApp.changeTheme(event, this)&quot;&gt;<br \/>            &lt;span class=&quot;ui-text&quot;&gt;Voclain&lt;\/span&gt;&lt;\/a&gt;<br \/>    &lt;\/div&gt;<br \/>&lt;\/span&gt;<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Update 12\/5\/2017 Note that there are issues when trying to use the standard themes loaded by the PrimeNG installation, which reside under node_modules. Basically, the traditional use of the link tag did not work even though the style files were present.&#160; This appears to be an issue relating to how the application is packaged and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[209],"tags":[164,16,15],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2060"}],"collection":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2060"}],"version-history":[{"count":7,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2060\/revisions"}],"predecessor-version":[{"id":2092,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2060\/revisions\/2092"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}