Skins & Templates

Introduction

Back to the manual

So, you've installed Nucleus... You've got several options now concerning the look of your site:

  1. Go with the default skin/templates that comes with Nucleus
  2. Start from the default skin/templates, and modify it to your needs (colors, etc...)
  3. Start your own skin/templates, and define your own CSS stylesheets

This document tries to help you with doing this.

Table Of Contents

HTML and CSS back to top

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:

The default skin back to top

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

The default skin uses three files:

  1. default.css: CSS stylesheet that defines the page style. Colors, layout etc. are defined in this file
  2. atom.gif: The logo that appears in the upper left corner of the screen
  3. nucleus2.gif: Nucleus logo

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

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

Templates vs. Skins back to top

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

  1. Skins 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.
  2. Ha! This means templates 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.

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.

Skins and Templates example

How skins are chosen back to top

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

Skin Types

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.

Query String FormatWhich skin type?Which weblog is shown?
?itemid=..itemDeducted from itemid
?archive=..archiveDefault weblog, or blogid attribute
?archivelist=...archivelistarchivelist-attribute
?archivelistarchivelistDefault weblog
?query=...searchDefault weblog, or blogid attribute
?memberid=..memberNone
?imagepopup=..imagepopupNone (popup window with image)
(other or empty)indexDefault weblog, or blogid attribute

Next to these 7 types, there is an error type, which is used when errors occur.

The Skin Cascade

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.

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.

The 'default' Skin

Nucleus requires that at all times there exists a skin called 'default'. 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.

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)

Howto: An 'add item' form on your website back to top

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.

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

1. JavaScript code

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

<script type="text/javascript"
        src="nucleus/javascript/edit.js"></script>

2. Indicate where the form will show up

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.

<div id="edit" style="display:none;">
...
</div>

3. Code that inserts the form and preview

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

<h2>Add Item</h2>
<%additemform%>

<h2>Preview</h2>
<%preview(mytemplate)%>

4. The 'add item'-link

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:

<a href="javascript:showedit();">add item</a>

The second example is a hidden button in the topleft corner

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

Howto: CSS to define the look of forms back to top

Through variables such as <%searchform%> and <%commentform%>, 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.

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

Form Type Skin Variable CSS Class Name
Add Item to Blog <%additemform%> .blogform
Add Comment <%commentform%> .commentform
Login Form <%loginform%> .loginform
Search Form <%searchform%> .searchform
Member to Member Mail <%membermailform%> .mailform

Below is an overview of the CSS classes assigned to buttons and input fields.

Type CSS Class Name
Input fields (text and textarea) .formfield
Buttons .formbutton

An example of how to use these classes in you stylesheets is given below:

/* 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;
}

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.

Howto: Enabling karma votes back to top

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

1. Open the template for the main index

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

2. Edit the 'Item body' template-part

Edit the bottom part of the item body templatepart to be as follows:

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

On the main page, the iteminfo line for the items will now look like:

9:00:39 PM - God - karma: 5 [+/-] - edit

3. Template for the detailed pages

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 'detailed'

Howto: 'edit item' links back to top

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.

'editlink'-template

The 'Edit Link'-templatepart defines how an 'edit item'-link is formatted. By default, the contents is:

<a href="<%editlink%>" onclick="<%editpopupcode%>">edit</a>

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

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

Positioning the edit-link

Next to the 'editlink' template, there's the <%edit%>-templatevar that, when placed somewhere in the 'item body'-templatepart, inserts the editlink.

See the example from the karma votes howto to see an example.