Path

ez.no / ezpublish / documentation / building an ez publish site / the news page / overview of the latest news


Overview of the latest news

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

The main menu (just below the site-banner) contains a link called "News". When this link is accessed, eZ publish should display the seven latest news articles. We'll achieve this functionality by creating a custom version of the "Folder" content class' full-view template. The full-view template will list the children of the node that is being accessed. Each child will be shown using a custom line-view template.

Fixing the menu
First, we have to make sure that the link in the menu works. The following piece of code takes care of this:

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

Insert this code into the "pagelayout.tpl" file (replace the previous News-link). Note that we're not telling eZ publish the ID of the node that contains the "News" folder. We're using the URL alias of the "News" folder, which is "news". The URL alias is piped into the "ezurl" operator. The operator takes care of setting the correct path based on the siteaccess settings.

Browse the TSCM site. Click on the "News" link. eZ publish will then display the contents of the "News" folder using the standard full-view folder template. A standard line-view template will be used to display each child of the folder. The browser should display something that resembles the following screenshot:

Creating custom templates
The following text explains how to generate a custom full-view-template for the "Folder" content class within the "News" section.

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

This will generate an empty file ("design/tscm/override/templates/full_view_news_folder.tpl") and instruct eZ publish to use it every time a folder in the "News section" is viewed. Put the following lines into the file, raise the priority (with 1 being the highest), and clear the cache.

<h1>Latest news</h1>

 

{* Grab some of the content of the node that is being viewed. *}

{let children=fetch( content, list, hash( parent_node_id, $node.node_id,

                                    sort_by, $node.sort_array,

                                    limit, 7,

                                    class_filter_type, include,

                                    class_filter_array, array( 'article' ) ) )}

 

{* LOOP: For each child of the node... *}

{section name=Child loop=$children}

 

   {* Display the content of the child using a line-view template. *}

   {node_view_gui view=line content_node=$Child:item}

 

   <hr>

 

{* End of loop. *}

{/section}

 

{* End of namespace. *}

{/let}

This piece of template code does the following:

  • Displays the name of the node that is being viewed.
  • Grabs the seven most recent articles from the node that is being viewed.
  • Displays the grabbed articles using a line-view template.

Try to access the "News" page again (either by refreshing the page or by clicking on the "News" link on the main menu). You should be presented with something like this:

The newly generated full-view template will automatically make use of the standard line-view template. The following text explains how to create a custom template for the line-view of the "Article" class within the "News section".

  1. Bring up the admininstration interface.
  2. Click on the "Design" tab.
  3. Click on "Templates" (in the menu on the left hand side).
    A list of template files will appear.
  4. Locate "/node/view/line.tpl" and click on it.
  5. On the next page, simply click "New override".
  6. Type in "line_view_news_article" into the "Name" field.
  7. Set the "Class" dropdown box to "Article".
  8. Set the "Selection" dropdown box to "News section".
  9. Do not enter anything into the node field (leave it blank).
  10. In the "Base template on" section, select "Emtpy file".
  11. Click "OK".

This will generate the "design/tscm/override/templates/line_view_news_article.tpl" template file. eZ publish will use this template every time it is instructed to display a list-view of article objects within the "News section". Put the following lines into the file:

<table class="latest_news">

   <tr>

       <td colspan="2">

           <div class="headline_link">

               <a href={$node.url_alias|ezurl}>

                   {attribute_view_gui attribute=$node.object.data_map.title}

               </a>

           </div>

       </td>

   </tr>

   <tr>

       <td>

           {attribute_view_gui attribute=$node.object.data_map.intro}

       </td>

       <td valign="top">

           <a href={$node.url_alias|ezurl}>

               {attribute_view_gui attribute=$node.object.data_map.image image_class="small"}

           </a>

       </td>

   </tr>

</table>

This code snippet takes care of getting and displaying some the contents of a news article. For each article, the headline, the intro and the article's thumbnail image is displayed. Browse the "News" page again. You should be looking at a page that resembles the following screenshot:

Comments

Watch out for permissions!

Read this (Scott Terry's permission note):
http://ez.no/community/forum/setu...tes_being_created_in_wrong_directory

Apparently, ezPublish looks at the permissions of the design/ and settings/ files and subdirectories. If the user PHP runs as (httpd, usually) doesn't have full write access on both dirs and files, it will place the new override template where it has.

If you've been following this tutorial and at some point have created new siteaccesses, you most likely didn't place proper permissions on them. The proper permissions are 770 for directories and 660 for files. Go around design and siteaccess and do this:

find design/ -type f -exec chmod 660 {} \;
find design/ -type d -exec chmod 770 {} \;
(repeat for siteaccess/)

If you don't, here's what happens: when you click "New override", the message will say it's gonna place the new override in design/admin/override/templates instead of your design dir, and you'll spend a while wondering if perhaps you should select a different siteaccess from the "Set" dropdown list, and what happens if you have several siteaccesses, and so on.

The big gotcha is that the "Set" dropdown list is just a "view" filter, it doesn't decide where the new templete override goes. The folder permissions do.

Also a good idea would be to take a look here:
http://ez.no/community/forum/gene...t_tpl_and_site_css_strange_behaviour

...and make sure your AvailableSiteDesignList includes all your own designs, otherwise you may end up wondering why the template cache doesn't clear even if you clear it manually.

url alias /news -> /content/view/full/node_id

This may be obvious but I thought I would share ... I couldn't see how a link in the template to /news was being translated to the system url /content/view/full/node_id_of_news_folder without manually setting up some URL translation under the setup tab.

Transpires that automatic URL aliases are "generated from the object names of the parent object, i.e. the "path". It will convert the name to lower case 0-9 a-z and _ characters", when you include in site.ini

[URLTranslator]
Translation=enabled

So a folder just under the root node of "Archive of Old News Articles" can be referenced using the url alias path "/archive_of_old_news_articles".

See http://ez.no/community/forum/setup_design/nice_urls
and http://ez.no/ez_publish/documenta...ation/tips_tricks/creating_nice_urls

showing thumbnail image

There are 2 steps to the process. the first is uploading the image and having it related to the news story. You can upload numerous things and have them be related to that news story.

the second part is assigning an image to the news story. In the image section of the news story you need to "Find Object" and then click on the "Media Library" tab at teh top of the page and then click on the "Images" link in the middle of the page and then select the image you want to display.

Then you can send for publishing and it should show up properly. The directions don't really address the two different phases of associating and then assigning.

Hope that helps......

not showing thumbnail text

This view doesn't show the thumbnail image text in this example...
Anyone with any suggestions to fix this?

'line_view_news_article' final steps

For 'line_view_news_article', don't forget to raise the priority and clear the cache.

Class dropdown menu doesn't have Folder or Article as in option in 3.5 RC1

Under Override keys, Classes only has "All classes" as an option. Leaving it as All classes breaks the display of individual news items, of course (found this out by trying it).

This has been fixed in the trunk.

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

22/10/2003
1:37:17 pm
by Balazs Halasy

Last updated

23/11/2004
2:51:01 pm
by Sandro Groganz

Authors

Balazs Halasy
Raymond Bosman
Sandro Groganz



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.