"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.

eZ debug

Timing: Jan 18 2025 19:20:31
Script start
Timing: Jan 18 2025 19:20:31
Module start 'layout'
Timing: Jan 18 2025 19:20:31
Module start 'content'
Timing: Jan 18 2025 19:20:31
Module end 'content'
Timing: Jan 18 2025 19:20:31
Script end

Main resources:

Total runtime0.0210 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0094 587.7891152.6094
Module start 'layout' 0.00940.0036 740.398439.4297
Module start 'content' 0.01300.0059 779.828193.3203
Module end 'content' 0.01890.0021 873.148434.3047
Script end 0.0209  907.4531 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003416.1048140.0002
Check MTime0.00125.8189140.0001
Mysql Total
Database connection0.00115.216310.0011
Mysqli_queries0.004220.100130.0014
Looping result0.00000.071610.0000
Template Total0.00167.810.0016
Template load0.00094.387510.0009
Template processing0.00073.376710.0007
Override
Cache load0.00062.985610.0006
General
dbfile0.00031.330280.0000
String conversion0.00000.037540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0003 secs