Newscoop 4 Cookbook

Sections

Sections are distinct clusters of articles. You will have seen sections in most print publications: Culture, Business, Sports, International Affairs, and so on. Usually these sections are visible in the publication's navigation; below you can see an example for the sample publication "The Journal". In this case, the section POLITICS is active, either because the reader is looking at the content of this section, or is reading an article inside the section:

Sections can be translated, and sections also have a description which can be added in the administration interface. The Newscoop developers are currently working on access levels for editors and journalists along section lines, meaning that you can assign your staff to sections and they are only allowed to work inside that section.

Here you can see the $gimme->section object in action:

 <h3>Section No.{{ $gimme->section->number }}: {{ $gimme->section->name }}</h3> {{ $gimme->section->description }} <ul>     <li>Published: {{ $gimme->section->publish_date|camp_date_format:"%e. %M %Y" }}</li>     <li>Using template: {{ $gimme->section->template->name }}</li>     <li>Inside: {{ $gimme->section->publication->name }}/{{ $gimme->section->issue->name }}</li>     <li>URL name: .../{{ $gimme->section->url_name }}/</li> </ul> 

This displays something along these lines, depending on where you are, in "The Journal":

Section No.40: Health

All the things that do you good.

  • Published: 20. April 2011
  • Using template: set_thejournal/section.tpl
  • Inside: The Journal/January 2011
  • URL name: .../health/

Note: A section's publishing date is the same as the publishing date of the issue.

Using $gimme->section in the navigation template

In your navigation, you can use $gimme->section to check which element of the navigation needs to be active, because this is the section the reader is in (example taken from_tpl/top-nav.tpl of "The Journal"):

 {{ list_sections }}     <li class="cat-item{{ if $gimme->section->number ==     $gimme->default_section->number }} current_page_item{{ /if }}">         <a href="{{ uri options="section" }}" title="View all posts filed under {{ $gimme->section->name }}">{{ $gimme->section->name }}</a>     </li> {{ /list_sections }} 

{{ if $gimme->section->number == $gimme->default_section->number }} checks if the section number provided by the list function is identical with the one of the page. If this is the case, an additional class is added. This class is then used in the CSS to style this element.

Listing Sections

In the above example, list_sections was already introduced. The list commands (for issues, sections, articles, languages, comments and others) can be tuned in many ways. A full reference can be found at the end of this manual.

Lists are usually not so elaborate when used on sections. You'll find more interesting examples in the chapter on articles. For sections, ordering is probably the most commonly used feature. Here are some examples; ordering by number (ascending):

 {{ list_sections order="bynumber asc" }}     {{ $gimme->section->number }}. {{ $gimme->section->name }} {{ /list_sections }} 
..or ordering by number (descending):
 {{ list_sections order="bynumber desc" }}     {{ $gimme->section->number }}. {{ $gimme->section->name }} {{ /list_sections }} 

This returns the section numbers in ascending or descending order, and also lists their names.

Setting and Unsetting Section

You can also change the section's values in the templates. In the following example this is done to access the static pages in section number 5 of the first issue (the example is taken from _tpl/footer.tpl of "The Journal" sample publication):

 {{ set_issue number="1" }} {{ set_section number="5" }} {{ list_articles }}     <li class="page_item"><a href="{{ uri options="article" }}" title="{{ $gimme->article->name }}">{{ $gimme->article->name }}</a></li> {{ /list_articles }} 

You can set the section name and the section number. You can reverse the section to the default value (the value for the default runtime environment of the displayed page):

 {{ set_default_section }} 

If you want to drop the information, you can use:

 {{ unset_section }} 

Unsetting a section does not lose the section information forever, it can be set with the above commands back to default, or an assigned value.