News archive

These documentation pages are no longer maintained. Please visit the new documentation site.

In the news archive, we simply wish to list all the news articles that have been published. The list should contain the headline/title of the articles and the date they were published.

We could produce the archive by overriding the folder class' standard full-view template within the news section. However, this template has already been overridden when we created a custom template for the news page. A possible solution is to create a new view. We'll call it "archive-view". The following text explains how to create a new view and how to make a custom template for it. In addition, the manual creation of an URL alias is also explained; we'll create a friendly URL for the news archive.

Creating a new view
The following text explains how to create a new view.

  1. Create the following directories:
    "design/tscm/templates/node"
    "design/tscm/templates/node/view"
  2. Create an empty file and save it as "design/tscm/templates/node/view/archive.tpl".

Creating a custom template
The following text explains how to create a custom template for the newly created view.

  1. Bring up the administration interface.
    Click on the "Design" tab.
    Click on "Templates" (in the menu on the left hand side).
    A list of template files will appear.
  2. Jump to the last page by using the navigator at the bottom of the page.
  3. Locate "/node/view/archive.tpl" and click on it.
  4. On the next page, click "New override".
  5. Type in "archive_view_news_folder" into the "Filename" field.
  6. Set the "Class" dropdown box to "Folder".
  7. Set the "Selection" dropdown box to "News section".
  8. Do not enter anything into the node field (leave it blank).
  9. In the "Base template on" section, select "Empty file".
  10. Click "OK".

This will generate the "design/tscm/override/templates/archive_view_news_folder.tpl" template file. eZ publish will use this template every time it is instructed to display an archive-view of a folder within the News section. Put the following lines into the newly created template file:

<div class="pagetitle">

   News archive

</div>

 

{* Grab all the news articles. *}

{let children=fetch( content,

                    list,

                    hash( parent_node_id, $node.node_id,

                          sort_by, $node.sort_array,

                          class_filter_type, include,

                          class_filter_array, array( 'article' ) 

                        )

                   )

}

 

<table class="news_archive">

   <tr>

       <td>

           <b>Article:</b>

       </td>

       <td>

           <b>Published:</b>

       </td>

   </tr>

 

   {* Loop through all articles that we just fetched. *}

   {section name=Child loop=$children}

   <tr>

       <td>

           {* Display a link to the article. *}

           <a href={$:item.url_alias|ezurl}>{$:item.name}</a>

           <br />

       </td>

       <td>

           {* Display the date the article was published. *}

           {$:item.object.published|l10n(shortdate)}

       </td>

   </tr>

   {* End of loop. *}

   {/section}

</table>

 

{/let}

This code will take care of listing all the news articles that are published in a nice fashion.

Creating an URL alias for the News archive
At this point, the news archive can only be reached using a system URL that tells eZ publish which view to use and which node to show ("[...]/content/view/archive/[node-number]" - where [node-number] is the identification number of the node that "contains" the News folder object). In order to be able to reach the news archive using a friendly URL, we must manually create a URL alias for it. The following text explains how to do this.

  1. Bring up the admininstration interface.
  2. Click on the "Content" tab.
    The system will display contents of the root folder.
  3. While hovering your mouse pointer over the "News" folder, a text pops up revealing the Node ID. Make a note of the node number.
  4. Click on the "Setup" tab.
  5. Click on "URL translator" (in the menu on the left hand side).
  6. In the "Old URL" field, type in: "/news/archive"
  7. In the "System URL" field, type in: "content/view/archive/[number]
  8. Click "Add".

What we have done is that we've instructed eZ publish to recognize the friendly URL, and when accessed, display the news archive. At this point, you should be able to access the news archive using both the system URL and the newly created virtual URL:

  • http://[...]/index.php/tscm/content/view/archive/[node-ID-of-News-folder]
  • http://[...]/index.php/tscm/news/archive

The following text explains how to create a link that can be used to access the news archive.

Creating the actual link to the archive
We will make the archive accessible from the bottom of the latest news page. Insert the following code at the end of the "design/tscm/override/templates/full_view_news_folder.tpl" file:

<br>

<div class="center">

<a href={"/news/archive"|ezurl}>

Click here to access the news archive...

</a>

</div>

Comments

In the "Old URL" field, type in: "/news/archive"?

Hi,
Can you tell me the "/archive" is predefined directory or create myself in root directory.
Thanks..........

Web directory you're altering

I couldn't find the self-made template either, until I saw I wasn't working in the correct SiteAccess. The pull-down menu on the top of the Menu Management window was set to the default Admin, not to TSCM.

Setting this will add the template to your list (once returnng to the templates). It may not appear on the exact last page. If not, check the page before it.

Creating an URL alias for the News archive errata

In the procedure of creating the URL alias for the NewsAchive you need the 'New System URL forwarding' part of the URL Translator.
In step 6 it should say 'Virtual URL' where it reads 'Old URL'

/node/view/archive.tpl

I couldn't find it in the complete list of templates, but it did appear in the Most Common Templates list beneath it. BTW Fredrik does the web server have premissions to change into the design/tscm/templates/node/view directory?

Re: Can't locate "/node/view/archive.tpl"

Try:

http://[...]/index.php/tscm_admin/visual/templateview/node/view/archive.tpl

Can't locate "/node/view/archive.tpl"

This didn't work for me. I created the empty archive.tpl file in the right folder but the template is nowhere to be found in the list.

Any ideas?

/Fredrik

Contents

Building an eZ publish site

Prerequisits
Situation
Creating the TSCM site
Testing the interfaces
Setting up the main layout
Creating sections
The welcome page
The news page
    Adding news articles
    Assigning the News folder to the News...
    Overview of the latest news
    Full display of an article
    News archive
The members page
The guestbook
The links page


Created

23/10/2003
9:59:38 am
by Balazs Halasy

Last updated

23/11/2004
2:14:01 pm
by Raymond Bosman

Authors

Balazs Halasy
Raymond Bosman



This page is part of the eZ Publish documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.