Examples of Using News Lists

How to create a list of 10 latest news articles

  • Create the channel sitenews.

  • Create the file format newsitem and activate its option Mark as new on the live server (canCreateNewsItems).

  • Create the file news1 anywhere in the folder hierarchy. Use newsitem as the format of the file.

  • Add code like this to the layout of the starting page:

    <ul>
      <npsobj newslist="all" length="10">
        <li>
          <npsobj insertvalue="anchor" name="self">
            <npsobj insertvalue="var" name="title" />
          </npsobj>
        </li>
      </npsobj>
    </ul>

How to create an RSS feed for politics news

  • Create the channel politics.

  • Create the file format newsitem and enable its option Mark as news on the live server (canCreateNewsItems).

  • Define a field description. Create the file format feed and add the description field to it. Do not activate canCreateNewsItems for feed.

  • Create the folder rssfeeds.

  • In the folder create a base layout which outputs an RSS feed (see below).

  • In the same folder create the file politicsfeed using the feed format and set its description to "Company policy news". Assign to it the politics channel.

  • Set the main content of the base layout to the following:

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.92//EN"
        "http://my.netscape.com/publish/formats/rss-0.92.dtd">
    <rss version="0.92">
    <channel>
      <description>
        <npsobj insertvalue="var" name="description" />
      </description>
      <language>de</language>
      <title><npsobj insertvalue="var" name="title" /></title>
      <link>http://www.mysite.com/</link>
      <copyright>(c) JustRelate Group GmbH</copyright>
      <generator>CMS Fiona 6.7.0</generator>
      <ttl>60</ttl>
      <npsobj newslist="selected" name="channels" length="20">
        <item>
          <title><npsobj insertvalue="var" name="title"/></title>
          <link>http://www.mysite.de<npsobj insertvalue="var" name="visiblePath" /></link>
          <description>
            <npsobj insertvalue="var" name="description"/>
          </description>
        </item>
      </npsobj>
    </channel>
    </rss>

To output the RSS feed in a different version (for example 2.0) you can modify the layout file as desired.

To generate another feed for sports news using the layout file above:

  • Create a channel named sports.

  • In the rssfeeds folder create the file politicsfeed using the feed format and set the file’s description field to "Latest sports news". As channels select sports.

  • Now create files based on the newsitem format and set their channels field to sports. The files will be added to the Sports news feed.

Sending a Newsletter

  • Create a folder named newsletters.

  • Write a base layout that generates the contents of the newsletter by reading fields from the corresponding files, for example.

  • Create a file format named newsletter.

  • In the newsletters folder create the file politics based on the file format newsletters.

  • Into the main content of the politics file enter the e-mail addresses. Only one address per line.

  • Write a wizard that sends the exportBlob field of politics to each e-mail address in the main content of politics.