Sourcefabric Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Newscoop 4.3 Cookbook

$gimme all your lovin'

Now that you're venturing into the territory of Newscoop, $gimme serves as your map and compass. $gimme is your reliable friend, your eager spy and the keeper of all knowledge. $gimme will give you information and answer your questions. "Give me the name of the article", "Give me the number of the issue", are requests $gimme will follow without even a shrug. Obviously, "give me" is how $gimme got its name. And $gimme speaks a simple language, along the lines of "gimme publication name" or "gimme user email."

$gimme and the Newscoop template language

We like to refer to Newscoop's template language as a programming language for news. $gimme lets you list and arrange articles, display text and multimedia, prepare content for third-party services and include external content. It allows editors total design freedom and doesn't push them into a single way of presenting their stories.

Easy to use, easy to read

The philosophy behind the Newscoop template language (and $gimme) has been to make it as intuitive and easy to use as possible. Here's how you would use $gimme to display the name (or headline) of an article, like "Newscoop 4 Cookbook now in shops":

{{ $gimme->article->name }}

Here's how you would use $gimme to display a section's description, such as "Film Reviews from the Venice Film Festival"

{{ $gimme->section->description }}

Display the date when an issue was published:

{{ $gimme->issue->publish_date }}

Display the file name of an article attachment:

{{ $gimme->article->attachment->file_name }}

Display the caption of an image, like "Work started at Berlin's new airport":

{{ $gimme->image->caption }}

Display the map provider you're using for your site's base maps:

{{ $gimme->map->provider }}

Here are some more examples along the same lines:

{{ $gimme->article->keywords }}

{{ $gimme->article->comment->subject }}

{{ $gimme->publication->default_language }}

{{ $gimme->author->name }}

{{ $gimme->author->biography->text }}

{{ $gimme->image->photographer }}

And there's more. In the following chapters you'll see $gimme in action, providing all kinds of information added by editors and journalists.

Separation of Presentation and Content

Web designers use the concept of "separation of presentation and content" every day when developing in HTML and CSS. In the HTML you can emphasize parts of the content with the em element, so whatever is wrapped inside <em> tags is "what" needs to be emphasized. "How" the emphasis is being displayed can be set in the CSS file, assigning font family, size, style, colour and so on.

Develop your design without touching any code

The Newscoop template engine gives you maximum flexibility to develop templates in HTML, CSS and JavaScript any way you like. You don't need to think in terms of blocks or widgets, and you can use sample text like "Lorem ipsum" when fine-tuning your layout. Turning your design into a template for Newscoop means to replace the sample text with $gimme. Here is a simple example. Here's the HTML we want to serve:

<div>Media and Journalism</div>
<h2>Newscoop Cookbook released</h2>
Anything web developers need to know about the CMS for professional journalists in one comprehensive desktop reference

Separating content from presentation in the Newscoop template engine, we call in $gimme to give us what we need:

<div>{{ $gimme->section->name }}</div>
<h2>{{ $gimme->article->name }}</h2>
{{ $gimme->article->subtitle }}

Note that $gimme->article->name is wrapped in two curly brackets on either side. There's also a white space between the brackets on either side - while it's not mandatory, it's a good practice to make the template code more readable - but there are no whitespaces in $gimme->article->name. The template engine operates on the simple premise that it finds two opening and closing brackets, takes out anything in between and tries to make sense of it, replacing it with content from the database.

Once the logic is in place, the design can be changed any way you want:

<div class="section">{{ $gimme->section->name }}</div>
<h2 class="title">{{ $gimme->article->name }}</h2>
<span>{{ $gimme->article->subtitle }}</span>

Or you can add even more material to control the design with CSS later:

<div class="wrapper">
    <h2 class="title section{{ $gimme->section->number }}">
       {{ $gimme->article->name }}</h2>
         <span>{{ $gimme->article->subtitle }}</span>
           <div class="section">{{ $gimme->section->name }}</div>

Note how in the <h2> tag, a class is being added here that will change its value depending on the section the article is coming from. The interface designer can develop the look and feel of the publication without having to go back to the programmer. Instead, all that needs to be changed is the template.

Watch $gimme at work

On its own, $gimme can pull information out of the content database and place it inside your template. When you set it loose inside Newscoop templates, it advances to become the project leader of your publication; beyond simple retrievals and replacements, $gimme is then in charge of making design decisions. Checking information with $gimme can create the most complex designs in very few lines of code.

To put $gimme into action, you'll use functions from the Newscoop template language. These functions are developed with the news organisation in mind, delivering publication content with simple commands. The functions available are being expanded continuously alongside new features in Newscoop, and an expanding range of features for already existing functionality. A complete Newscoop template design reference is included towards the end of this Cookbook.

Now let's take a peek into an actual code snippet using $gimme. In this case you'll see a Newscoop function alongside $gimme. The function is called list_article_authors. Everything inside this function (it has a closing tag like in HTML) is repeated as many times as there are authors who have worked on this article.

The following example - in plain English - would be like asking $gimme: "Could you please list all the authors that worked on this article?"

Lets look at the code step by step and keep telling $gimme what to do.

{{ list_article_authors }}

For each author, we want the last name and then the first name separated by a comma.

<strong>{{ $gimme->author->last_name }}</strong>,
{{ $gimme->author->first_name }}<br />

Also show their image.

<img src="{{ $gimme->author->picture->imageurl }}" />

Very important, show their full name alongside their work field (author, photographer, etc.), followed by their e-mail and their biography.

{{ $gimme->author->name }} ({{ $gimme->author->type }}):
<a href="mailto:{{ $gimme->author->email }}">{{ $gimme->author->email }}</a>
{{ $gimme->author->biography->text }}

When you are done, close this list. Thanks.

{{ /list_article_authors }}

You can see how $gimme makes it easy to pull up information in your templates. There is a quite a lot happening in twelve lines of code. We are delivering a list of authors alongside images, biography and e-mail. This will look great in the header of the article.

After this very straightforward example, we'll leap ahead into using maps inside articles (covered in detail later in this Cookbook). The following code will list the name and geo-location information for an article. Note that only "enabled" locations are listed, because the journalist might still be working on the map in the administration interface. Once a location is set to be seen by the public, it shows up using this code:

{{ list_article_locations }}
    {{ if $gimme->location->enabled }}
        {{ $gimme->location->name }}<br />
        {{ $gimme->location->longitude }}, {{ $gimme->location->latitude }}
    {{ /if }}
{{ /list_article_locations }}

We bet you've already started loving the power of $gimme. Besides $gimme, the Newscoop template language includes a complete set of functions and several other powerful capabilities that are condensed in the Newscoop Template Reference.

There's more...

The Newscoop template language is an extension to a popular and powerful template engine called Smarty, which itself is written in PHP. Smarty is popular among PHP users and developers, and comes with a rich set of functionality you can use in your templates. You will see some examples in this Cookbook and find a full reference online at

With each Newscoop version the template language and $gimme become more powerful. We keep developing and integrating new features, and extending the current ones, but we do also care about backward compatibility, which means we are not going to break your current website.

Once you understand the power of $gimme, you will start getting a sense of the freedom it offers you when building websites. Enjoy!

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.