"Read more..." link

Author Message

Franck T.

Thursday 19 August 2004 1:09:23 am

Hello everybody.
In my welcome page, I'd like to display a "Read more" link to an article. This is my code wich override the /node/view/full/tpl for my welcome page node.

...
<div class="pagetitle">
    {attribute_view_gui attribute=$node.object.data_map.title}
</div>
<div class="imageright">
    {attribute_view_gui attribute=$node.object.data_map.image}
</div>
{$node.object.published|l10n(date)}
{attribute_view_gui attribute=$node.object.data_map.intro}
{* attribute_view_gui attribute=$node.object.data_map.body *}
{* section show=$node.object.data_map.body.content.is_empty|not}
        <div class="attribute-link">
            <p><a href={$node.url_alias|ezurl}>{"Read more..."|i18n("design/base")}</a></p>
        </div>
    {/section *}

The more important is the "Read more" link. When click I get... nothing than the same page, like a recursive call!
My (beginner) question is how to dispaly the full article when clicking on the link ?
And a second please: is there a way to display this kind of link depending on the article size? I mean display the link for long articles (more than 15 lines for example) and directly display the full content for short articles.
Thanks a lot.

Trond Åge Kvalø

Thursday 19 August 2004 1:56:41 am

Hi

The $node variable gives you the current node object. So $node.url_alias|ezurl points to the page you are currently on. That's correct behaviour on eZ's side here.

Now usually you place your articles in for instance a news folder. Let's pretend that the node_id of this news folder is 42. Then you fetch all the articles that resides in that folder by using the fetch function like this:

{let articles = fetch( 'content', 'list', hash( 'parent_node_id', 42) ) }

Now all the articles are placed in an array called articles. The next thing to do will be to loop through that array and extract the needed information. For that we use the template function "section". If we want to show Title, Publish date, Intro and a link to the article on the front page, this is how we do it:

{section loop=$articles}
<div class="pagetitle">
    {attribute_view_gui attribute=$:item.object.data_map.title}
</div>
{$:item.object.published|l10n(date)}
{attribute_view_gui attribute=$:item.object.data_map.intro}
{section show=$:item.object.data_map.body.content.is_empty|not}
  <div class="attribute-link">
    <p><a href={$:item.url_alias|ezurl}>{"Read more..."|i18n("design/base")}</a></p>
  </div>
{/section}
{/section}

Since we're looping an array here, I have replaced $node with $:item which is the current item in the loop. Thus you will display the article's attributes instead of the current node's attributes. This assumes that the articles have class attributes named Title, Intro, Image and so on.

A bit elaborate answer here, but the bottom line is: To show the full article you must use the article's link instead of the current node's link. To show the article's link you must first fetch the article(s) and place it in a variable. Then you must extract the correct data from this variable.

Useful links:
http://ez.no/ez_publish/documentation/reference/data_fetching/content
http://ez.no/ez_publish/documentation/reference/data_fetching/content/list
http://ez.no/ez_publish/documentation/customization/custom_design/variables_arrays_and_objects (First paragraph)

best regards
trondåge

trondåge

Franck T.

Thursday 19 August 2004 3:32:44 am

Thanks Trondåge for responding so brightly. You might be a good teacher...
I understand what you explain but there is still something odd: the article's link I get with your code AND my current position as displayed in my browser's adress bar <b> are the same ! </b>
So when I click on the link it moves to the place I'm already, just showing me the link but not the full article !!!!
'Going mad with this. Please tell me what to do !

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.