A template is a single file with the .tpl ending. Usually, a number of .tpl files plus Javascript, CSS and other files are combined into a theme. This Cookbook is intended to help you to create or modify templates and bundle them into a unique theme for your publication. Inside the theme, the individual template files are structured in folders and sub-folders. While there is a certain freedom about doing this, we encourage you to follow the "best practice" that we describe here.
It's not set in stone; you can structure your templates and folders however you prefer, but the Newscoop community has agreed on this structure after years of working with templates. The themes that Sourcefabric provides all feature this structure. If you use the same logic it will be easier to use examples or copy sub-templates from one theme to another. Read on to find out what we recommend when it comes to naming templates and placing them in your file system.
Every theme available for download from Sourcefabric has four main templates:
These are called - no surprise here - front.tpl, section.tpl, article.tpl and 404.tpl.
You could run a publication with these four templates and nothing else. But to make the most of the template engine's power, you should divide up your templates further, creating sub-templates which can be easily reused and edited.
There are some parts of pages which are identical, regardless of the section or the article. This is usually the case for the header, navigation and footer, for example. But it could also be an image stream from Flickr, a Twitter feed, a 'Like' button from Facebook, or a similar icon for sharing content from a third-party provider.
You don't have to duplicate this part of the template. In fact, it's even better to hand off these functions to sub-templates. Then when you apply a change to the sub-template, it will show up across your entire site.
You can take out sub-templates, place them in a subfolder and call them with an include, like this:
{{ include file="_tpl/article-comments.tpl" }}
As you can see in this example, the path to the template is relative. Inside a theme, all subfolders can be reached as relative paths. A typical part of a template might look like the following piece of code. This example is taken from the theme "Quetzal":
<section id="content">
<div>
{{ if $gimme->article->type_name == "debate" }}
{{ include file="_tpl/article-debate.tpl" }}
{{ else }}
{{ include file="_tpl/article-cont.tpl" }}
{{ /if }}
{{ include file="_tpl/article-aside.tpl" }}
</div> <!--end div class="row"-->
{{ include file="_tpl/tablet-more-tabs.tpl" }}
</section> <!-- end section id=content -->
Besides the main templates (front.tpl, section.tpl, article.tpl) you will probably have many sub-templates to run your publication. Depending on whether they're common across multiple pages, or unique to a page, you may follow these rules. But you don't have to, because Newscoop doesn't have reserved names for specific templates; it's really up to you to create your environment the way you like.
Let's take a look at a live Newscoop theme "The New Custodian" developed by Ljuba Rancovic:
https://github.com/newscoop/theme-NewCustodian
Inside this theme, files are structured inside folders. On the top level, you can only see a smaller number of template files, which call more detailed code from template files inside the _tpl folder.
From the sub-folders you see in this screenshot only one name is fixed: _conf. The others could be named any way you want. But to make things easier for other theme developers, better stick to the suggested structure. Here are the folders explained:
If you check out Sourcefabric template packages you will see that beyond this strict structure, we actually get a bit looser and let our hair down. For example, you'll find image folders inside the CSS folders, providing background images. A good rule of thumb would be keep your ship in order for as long as you can. Then get flexible and sail with the wind.
In order to call a template from within a template, you use the include command. Here are some examples of including static files:
<link rel="shortcut icon" href="{{ url static_file='_img/favicon.ico' }}" /> <link rel="stylesheet" href="{{ url static_file='_css/ui-lightness/jquery-ui.custom.css' }}" /> <script src="{{ url static_file='_js/libs/jquery.min.js' }}"></script> <link href="{{ url static_file="_css/video-js.css" }}" rel="stylesheet" />
And here are some examples of how to include template files:
{{ include file="_tpl/article-rating.tpl" }} <aside class="fourcol last">{{ include file="_tpl/article-aside.tpl" }}</aside>
The <aside> tag is new in HTML5.
There has been error in communication with Booktype server. Not sure right now where is the problem.
You should refresh this page.