Location: PHPKode > projects > Nucleus CMS Weblog > nucleus3.64/nucleus/documentation/skins.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
	<!-- $Id: skins.html 1457 2010-10-26 15:47:41Z ftruscot $ -->
	<title>Nucleus - Skins and Templates</title>
	<link rel="stylesheet" type="text/css" href="styles/manual.css" />
</head>
<body>

<div class="heading">
Skins &amp; Templates
</div>

<h1>Introduction</h1>

<p>
<a href="index.html">Back to the manual</a>
</p>

<p>So, you've installed Nucleus... You've got several options now concerning the look of your site:</p>
<ol>
	<li>Go with the default skin/templates that comes with Nucleus</li>
	<li>Start from the default skin/templates, and modify it to your needs (colors, etc...)</li>
	<li>Start your own skin/templates, and define your own CSS stylesheets</li>
	<li>Download one of the dozens of free skins available on the <a href="http://skins.nucleuscms.org/" title="Nucleus CMS skins">Nucleus Skins site</a>.</li>
</ol>
<p>This document tries to help you with doing this.</p>

<h1><a id="toc"></a>Table Of Contents</h1>

<ul>
	<li><a href="#htmlcss">HTML and CSS</a></li>
	<li><a href="#defaultskin">The default skin</a></li>
	<li><a href="#templatesvsskins">Templates vs. Skins</a></li>
	<li><a href="#skincascade">How skins are chosen</a></li>
	<li>Howto:
		<ul>
			<li><a href="#howto-additem">An 'add item' form on your website</a></li>
			<li><a href="#howto-cssforms">Using CSS to define the look of forms</a></li>
			<li><a href="#howto-karma">Enabling karma votes</a></li>
			<li><a href="#howto-edit">'Edit item'-links</a></li>
		</ul>
	</li>
	<li><a href="#export">Writing skins with Export/Import in mind</a></li>
</ul>

<h1>HTML and CSS <a id="htmlcss" href="#top" class="toplink"><img src="icon-up.gif" width="15" height="15" alt="back to top" /></a></h1>

<p>
When editing skins and templates, you'll need at least some basic knowledge about HTML and CSS. This section provides some pointers to online tutorials and references:
</p>

<ul>
	<li><a href="http://www.w3schools.com/">W3Schools</a>: online web building tutorials (HTML, XHTML, CSS)</li>
	<li><a href="http://thenoodleincident.com/tutorials/css/">CSS Panic Guide</a>: links to various CSS resources</li>
	<li><a href="http://hotwired.lycos.com/webmonkey/authoring/html_basics/index.html">Webmonkey: HTML Basics</a></li>
	<li><a href="http://hotwired.lycos.com/webmonkey/authoring/stylesheets/">Webmonkey: Stylesheets</a></li>
	<li><a href="http://diveintoaccessibility.org">Dive Into Accessibility</a>: Online book, not really about HTML, but about accessibility and how to make your site more accessible.</li>
</ul>







<h1>The default skin <a id="defaultskin" href="#top" class="toplink"><img src="icon-up.gif" width="15" height="15" alt="back to top" /></a></h1>

<p>This section briefly explains which files are used by the default skin, and how you can edit them.</p>

<p>The default skin uses three files:</p>
<ol>
	<li><tt>default.css</tt>: CSS stylesheet that defines the page style. Colors, layout etc. are defined in this file</li>
	<li><tt>atom.gif</tt>: The logo that appears in the upper left corner of the screen</li>
	<li><tt>nucleus2.gif</tt>: Nucleus logo</li>
</ol>

<p>The CSS file <tt>default.css</tt> contains extra information about how pages are built up by the default skins and templates. Basically, it comes down to three <tt>div</tt>-containers: <tt>.contents</tt>, <tt>.logo</tt> and <tt>.menu</tt></p>

<p>To edit the <tt>default.css</tt> file, you'll need a simple texteditor that does not add extra data, like Notepad (comes with windows),emacs or TextPad. Do <strong>not</strong> use WordPad, Word, OpenOffice Writer, ... since those add extra markup data.</p>






<h1>Templates vs. Skins <a id="templatesvsskins" href="#top" class="toplink"><img src="icon-up.gif" width="15" height="15" alt="back to top" /></a></h1>

<p>
In Nucleus, both templates and skins are used to determine the way your blog looks. So, what is the difference between these two?
</p>

<ol>
	<li>
		<b>Skins</b> define how your sites look. Each skin consists of several types: one for the main index, one for the detailed item pages, one for the archive, ...
		The skins also contain instructions of where to include a weblog, and which template should be used to do so.
	</li>
	<li>
		Ha! This means <b>templates</b> are used to define the way the weblog block in your page looks like. The reason why templates aren't included in the skins themselves, is that several skins can use the same template to display a blog.
	</li>
</ol>

<p>An example is given in the image below. The whole page is defined by a skin, while the parts in the red rectangles (category list and blog contents) are formatted according to the templates. It's the skin that defines where the red rectangles will appear.</p>

<div class="screenshot">
<img src="pics/skinsandtemplates.png" width="300" height="283" alt="Skins and Templates example" />
</div>









<h1>How skins are chosen <a id="skincascade" href="#top" class="toplink"><img src="icon-up.gif" width="15" height="15" alt="back to top" /></a></h1>

<p>
This section tries to explain how Nucleus chooses the skin to use when you request a page.
</p>

<h2>Skin Types</h2>

<p>
First of all, there are several skin types between which Nucleus makes a choice according to the request URL: see the list below. This should be very obvious.
</p>

<table>
	<tr><th>Query String Format</th><th>Which skin type?</th><th>Which weblog is shown?</th></tr>
	<tr><td>?itemid=..</td><td>item</td><td>Deducted from <i>itemid</i></td></tr>
	<tr><td>?archive=..</td><td>archive</td><td>Default weblog, or <i>blogid</i> attribute</td></tr>
	<tr><td>?archivelist=...</td><td>archivelist</td><td><i>archivelist</i>-attribute</td></tr>
	<tr><td>?archivelist</td><td>archivelist</td><td>Default weblog</td></tr>
	<tr><td>?query=...</td><td>search</td><td>Default weblog, or <i>blogid</i> attribute</td></tr>
	<tr><td>?memberid=..</td><td>member</td><td>None</td></tr>
	<tr><td>?imagepopup=..</td><td>imagepopup</td><td>None (popup window with image)</td></tr>
	<tr><td><i>(other or empty)</i></td><td>index</td><td>Default weblog, or <i>blogid</i> attribute</td
	></tr>
</table>

<p>
Next to these 7 types, there is an <i>error</i> type, which is used when errors occur.
</p>

<h2>The Skin Cascade</h2>

<p>
The table above also indicates how the blog to be displayed is chosen. The skin that will be used, is the default skin for that weblog, as selected in the settings for that weblog.
</p>

<p>
Not every skin needs to have definitions for all skin parts. When a part is missing, the skin called 'default' will be used instead (see below). This allows you for example to only create one error page and one member page.
</p>

<h2>The 'default' Skin</h2>

<p>
Nucleus requires that at all times there exists a skin called '<b>default</b>'. This is the skin to which is backed up when a skinpart is missing. If the same skinpart is also missing from the 'default' skin, the error message 'no appropriate skin found' will be shown.
</p>

<p>
Another reason why the 'default' skin is required, is to be able to display error messages when no blog is selected (e.g. the 'no such blog' error)
</p>








<h1>Howto: An 'add item' form on your website <a id="howto-additem" href="#top" class="toplink"><img src="icon-up.gif" width="15" height="15" alt="back to top" /></a></h1>

<p>
Nucleus provides facilities to add an 'add item' form to your weblog. It adds an 'add item' link that shows and hides the 'add item' form right above the current contents of your weblog. Entering text in this form results into an instant preview, so you can immediately see how the actual weblog item will look like.
</p>

<p>
All modifications below apply to the <b>skin</b> for the <b>main index</b> page. You don't need to alter any templates.
</p>

<h2>1. JavaScript code</h2>
<p>
First of all, you need to include the edit.js Javascript code by putting the following line somewhere in between the &lt;head&gt; and &lt;/head&gt; tags. This file contains the functions that are needed to make the preview work and to hide/show the 'add item' form.
</p>

<pre>
&lt;script type="text/javascript"
        src="nucleus/javascript/edit.js"&gt;&lt;/script&gt;
</pre>

<h2>2. Indicate where the form will show up</h2>

<p>
The, you add a logical container somewhere on your page, where you want to have the 'add item' form. The "display:none;" makes sure it is hidden.
</p>

<pre>
&lt;div id="edit" style="display:none;"&gt;
...
&lt;/div&gt;
</pre>

<h2>3. Code that inserts the form and preview</h2>

<p>
Now, you can add your custom HTML into this container, and use &lt;%additemform%&gt; and &lt;%preview(<i>templatename</i>)%&gt; to insert the 'add item' form and the preview code respectively. An example is given below
</p>

<pre>
&lt;h2&gt;Add Item&lt;/h2&gt;
&lt;%additemform%&gt;

&lt;h2&gt;Preview&lt;/h2&gt;
&lt;%preview(mytemplate)%&gt;
</pre>

<h2>4. The 'add item'-link</h2>
<p>
And the finishing touch: a link or button to trigger the visibility of the form. Two examples are given. The first one is a simple link:
</p>

<pre>
&lt;a href="javascript:showedit();"&gt;add item&lt;/a&gt;
</pre>

<p>
The second example is a hidden button in the topleft corner
</p>

<pre>
&lt;div style="position: absolute; left: 0px;
            top: 0px; width: 10px; height: 10px"
     onclick="javascript:showedit();"&gt;
&lt;/div&gt;
</pre>






<h1>Howto: CSS to define the look of forms <a id="howto-cssforms" href="#top" class="toplink"><img src="icon-up.gif" width="15" height="15" alt="back to top" /></a></h1>

<p>
Through variables such as &lt;%searchform%&gt; and &lt;%commentform%&gt;, forms can easily be included into your skin. To allow styles to be applied on those forms, CSS classes have been assigned to the input fields and buttons, and to a surrounding DIV-container.
</p>

<p>
Below is a list of which CSS class corresponds to which form. These are the classes assigned to the surrounding DIV-container.
</p>

<table>
	<tr>
		<th>Form Type</th>
		<th>Skin Variable</th>
		<th>CSS Class Name</th>
	</tr>
	<tr>
		<td>Add Item to Blog</td>
		<td>&lt;%additemform%&gt;</td>
		<td>.blogform</td>
	</tr>
	<tr>
		<td>Add Comment</td>
		<td>&lt;%commentform%&gt;</td>
		<td>.commentform</td>
	</tr>
	<tr>
		<td>Login Form</td>
		<td>&lt;%loginform%&gt;</td>
		<td>.loginform</td>
	</tr>
	<tr>
		<td>Search Form</td>
		<td>&lt;%searchform%&gt;</td>
		<td>.searchform</td>
	</tr>
	<tr>
		<td>Member to Member Mail</td>
		<td>&lt;%membermailform%&gt;</td>
		<td>.mailform</td>
	</tr>
</table>

<p>
Below is an overview of the CSS classes assigned to buttons and input fields.
</p>

<table>
	<tr>
		<th>Type</th>
		<th>CSS Class Name</th>
	</tr>
	<tr>
		<td>Input fields (text and textarea)</td>
		<td>.formfield</td>
	</tr>
	<tr>
		<td>Buttons</td>
		<td>.formbutton</td>
	</tr>
</table>

<p>
An example of how to use these classes in you stylesheets is given below:
</p>

<pre>
/* applies to all input fields */
.formfield {
  background-color: gray;
}

/* only applies to buttons for comment forms */
.commentform .formbutton {
  border: 1px solid #000;
  background-color: #ddd;
  color: #000;
  font-size: xx-large;
}
</pre>

<p>In the example above, all formfields that nucleus generates are given a gray background, and the submit button on the comment form has large text, a black 1px border, black text and a light-gray background.</p>


<h1>Howto: Enabling karma votes <a id="howto-karma" href="#top" class="toplink"><img src="icon-up.gif" width="15" height="15" alt="back to top" /></a></h1>

<p>The default skins and templates have karma votes disabled (better: left out). Here's how to add them to your <i>template</i>.</p>

<h2>1. Open the template for the main index</h2>

<p>Start editing the template named <tt>'default'</tt> (when starting from the default skins/templates that come with Nucleus)</p>

<h2>2. Edit the 'Item body' template-part</h2>

<p>Edit the <i>bottom part</i> of the item body templatepart to be as follows:</p>

<pre>
&lt;div class="iteminfo"&gt;
  &lt;%time%&gt; -
  &lt;a href="&lt;%authorlink%&gt;"&gt;&lt;%author%&gt;&lt;/a&gt; -
  karma: &lt;%karma%&gt;
    [&lt;a href="&lt;%karmaposlink%&gt;"&gt;+&lt;/a&gt;/&lt;a href="&lt;%karmaneglink%&gt;"&gt;-&lt;/a&gt;] -
  &lt;%edit%&gt;
  &lt;%comments%&gt;
&lt;/div&gt;
</pre>

<p>On the main page, the iteminfo line for the items will now look like:</p>

<div><i>9:00:39 PM - <a href="">God</a> - karma: 5 [<a href="">+</a>/<a href="">-</a>] - <a href="">edit</a></i></div>

<h2>3. Template for the detailed pages</h2>

<p>At this time, the karma score is only listed on the main page. To make it appear on the detailed page also, the same change needs to be applied to the template with name '<tt>detailed</tt>'</p>






<h1>Howto: 'edit item' links <a id="howto-edit" href="#top" class="toplink"><img src="icon-up.gif" width="15" height="15" alt="back to top" /></a></h1>

<p>The default Nucleus skin includes 'edit item'-links that are only visible to the author of a item and to the people having the right to alter the item. This section explains which template-parts are needed for this feature to work.</p>

<h2>'editlink'-template</h2>

<p>The 'Edit Link'-templatepart defines how an 'edit item'-link is formatted. By default, the contents is:</p>
<pre><code>&lt;a href="&lt;%editlink%&gt;" onclick="&lt;%editpopupcode%&gt;"&gt;edit&lt;/a&gt;</code></pre>

<p>If you would rather edit the item in the admin area, instead of in the popup bookmarklet, use the following code instead:</p>

<pre><code>&lt;a href="nucleus/index.php?action=itemedit&amp;amp;itemid=&lt;%itemid%&gt;"&gt;edit&lt;/a&gt;
</code></pre>

<h2>Positioning the edit-link</h2>

<p>Next to the 'editlink' template, there's the <code>&lt;%edit%&gt;</code>-templatevar that, when placed somewhere in the 'item body'-templatepart, inserts the editlink.</p>

<p>See the example from the <a href="#howto-karma">karma votes howto</a> to see an example.</p>




<h1>Writing skins with Export/Import in mind <a id="export" href="#top" class="toplink"><img src="icon-up.gif" width="15" height="15" alt="back to top" /></a></h1>

<p>Nucleus v2.0 introduced the ability to import and export skins and templates. This section describes the creation of a simple skin, highlighting the features involved.</p>

<h2>Creating a new skin</h2>

<ol>
	<li>
		<p>First, we're going to create a new skin from the admin area. Browse to <code>Nucleus Management &gt; Edit Skins</code> and scroll to the bottom of the page. Let's call this skin '<strong>vista</strong>'</p>
	</li>
	<li>
		<p>Now look up the 'vista' skin in the skin list and go to the <code>Edit</code> screen. The content type is set to <code>text/html</code>. That's what we want, so no need to change that</p>
		<p>The <code>Include Mode</code> and <code>Include Prefix</code> setting reuire more attention. To export a skin, we like to have all files (images, stylesheets, etc...) under one single directory. Remember the <code>$DIR_SKINS</code> setting in <code>config.php</code> and the <code>Skins URL</code> in the general site settings? Suppose these were as follows:</p>
		<pre><code>/home/user/example/htdocs/skins/
http://example.org/skins/</code></pre>
		<p>Then we would like to put our files in</p>
		<pre><code>/home/user/example/htdocs/skins/vista/
http://example.org/skins/vista/</code></pre>
		<p>And this is what the <strong><code>Include Mode</code></strong> is for. Setting it to <strong>Use skin dir</strong> will do this.</p>
		<p>The <strong><code>Include Prefix</code></strong> also plays a role. This is the <strong>vista/</strong> part</p>
		<p>An overview of the correct settings:</p>
		<ul>
			<li><strong>Name</strong>: vista</li>
			<li><strong>Content Type</strong>: text/html</li>
			<li><strong>Include Mode</strong>: Use skin dir</li>
			<li><strong>Include Prefix</strong>: vista/</li>
		</ul>
	</li>
</ol>

<h2>Edit the skin</h2>

<p>The <code>IncludeMode</code> and <code>IncludePrefix</code> settings will cause the <code>include</code>, <code>phpinclude</code> and <code>parsedinclude</code> skinvars to get their files from the skindir. Next to that, there's the <code>skinfile</code> skinvar, which translates its argument to an URL relative to the skinsdir.</p>

<p>In our case:</p>

<pre><code>&lt;%skinfile(myFile.jpg)%&gt;</code></pre>

<p>Will get expanded to:</p>

<pre><code>http://example.org/skins/vista/myFile.jpg</code></pre>

<p>Lets go easy on ourselves and define the global layout in two files called <code>pagefoot.inc</code> and <code>pagehead.inc</code>, which we place in our <code>vista/</code> directory:</p>

<h3>pagehead.inc</h3>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
	&lt;title&gt;My Site&lt;/title&gt;
	&lt;link rel="stylesheet" type="text/css" href="&lt;%skinfile(layout.css)%&gt;" /&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div id="contents"&gt;</code></pre>

<h3>pagefoot.inc</h3>

<pre><code>&lt;/div&gt;&lt;!-- contents div end --&gt;

&lt;div id="stuffbar"&gt;
	&lt;h2&gt;Navigation&lt;/h2&gt;

	&lt;ul&gt;
		&lt;li&gt;&lt;a href="&lt;%todaylink%&gt;"&gt;Today&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="&lt;%archivelink%&gt;"&gt;Archives&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;

	&lt;h2&gt;About&lt;/h2&gt;

	&lt;ul&gt;
		&lt;li&gt;&lt;a href="http://www.nucleuscms.org/"&gt;Nucleus&lt;/a&gt; Power!&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;&lt;!-- stuffbar end --&gt;

&lt;/body&gt;
&lt;/html&gt;</code></pre>

<p>The contents of the skinparts then becomes kind of trivial: (I'm not defining them all, you'll get the point by seeing the most important ones)</p>

<h3>Main Index</h3>
<pre><code>&lt;%parsedinclude(pagehead.inc)%&gt;

&lt;h1&gt;My Blog&lt;/h1&gt;

&lt;%blog(vista/main,10)%&gt;

&lt;%parsedinclude(pagefoot.inc)%&gt;</code></pre>

<h3>Item Pages</h3>

<pre><code>&lt;%parsedinclude(pagehead.inc)%&gt;

&lt;h1&gt;My Blog&lt;/h1&gt;

&lt;h2&gt;Item&lt;/h2&gt;
&lt;%item(vista/detailed)%&gt;

&lt;h2&gt;Comments&lt;/h2&gt;
&lt;%comments(vista/detailed)%&gt;

&lt;h2&gt;Add Comment&lt;/h2&gt;
&lt;%commentform%&gt;

&lt;%parsedinclude(pagefoot.inc)%&gt;</code></pre>

<p>Note that I named my templates <strong>vista/main</strong> and <strong>vista/detailed</strong>. Makes it easier to see things together six months later. Both templates are actually clones that I made of the <strong>default</strong> and <strong>detailed</strong> templates that come with Nucleus.</p>

<h3>Archive List</h3>

<pre><code>&lt;%parsedinclude(pagehead.inc)%&gt;

&lt;h1&gt;My Blog&lt;/h1&gt;

&lt;%archivelist(vista/main)%&gt;

&lt;%parsedinclude(pagefoot.inc)%&gt;</code></pre>

<h3>Archive</h3>

<pre><code>&lt;%parsedinclude(pagehead.inc)%&gt;

&lt;h1&gt;My Blog&lt;/h1&gt;

&lt;%archive(vista/main)%&gt;

&lt;%parsedinclude(pagefoot.inc)%&gt;</code></pre>

<h2>Export the skin</h2>

<p>When all is done, you can export the skin from the <code>Skin Import/Export</code> page in the admin area. Here's what to do:</p>

<ol>
	<li>Select vista, vista/detailed and vista/main from the skins and template list</li>
	<li>Add some textual description and hit the <code>Export selected skins/templates</code> button. It will generate a <code>skinbackup.xml</code> for you.</li>
	<li>Save this <code>skinbackup.xml</code> file together with the other files in the <code>vista/</code> directory.</li>
	<li>Package all files from the vista directory inside a zipfile</li>
	<li>All done! Your skin can now be shared with others</li>
</ol>

<h2>Importing a skin</h2>

<p>Importing is the reverse process:</p>

<ol>
	<li>Unzip the zip file under your skins directory, so you end up with a <code>vista/</code> dir (there will be one directory per skin)</li>
	<li>From the <code>Skin Import/Export</code> page in the admin area, select <code>vista</code> from the dropdown, and click the <code>Import</code> button.</li>
	<li>Follow the instructions</li>
	<li>The skin is now installed. It can be selected from the blogsettings.</li>
</ol>

</body>
</html>
Return current item: Nucleus CMS Weblog