Fetching confusion

Author Message

Bill Rust

Wednesday 26 March 2008 9:14:42 am

I'm being driven crazy by a piece of fetching that I'm unable to get right.

What I a want is for a list of 10 articles from node 66 to be displayed in one table column and then for a list of 10 articles from node 89 to be displayed in the right-hand column.

The following code produces some output but mixes all my articles together, seemingly randomly. Can anyone see where I am going wrong? I'm a little bit of a newbie to all this, I'm afraid!

{def $news_list=fetch( content, tree, hash( parent_node_id, 66,
                                           limit, 10,
                                           sort_by, array( published, false() ),
                                            ) )}

{def $newsone_list=fetch( content, tree, hash( parent_node_id, 89,
                                           limit, 10,
                                           sort_by, array( published, false() ),
                                            ) )}
<tr>
<ul>

{foreach $news_list as $key=> $news max 4 offset 2}
<li>
<td valign="top" width="50%">

{node_view_gui view=frontpagelisting
	content_node=$news}</li></foreach>
</td>

</ul>
</undef>
<ul>
{foreach $newsone_list as $key=> $newsone max 4 offset 1}
<li>
<td valign="top" width="50%">

{node_view_gui view=frontpagelisting
	content_node=$newsone}</li>
</foreach>
</td>
</ul>

</tr>
</undef>

Hans Melis

Wednesday 26 March 2008 10:19:43 am

I'm surprised that code even produces some output! The fetch operations are quite correct, but what follows is an absolute no-go: template code and HTML.

First a tip: you don't need multiple {def} statements. You can declare multiple variables in one {def} block, just separate the variables with a space.

Then a couple of questions:
1) What is the max and offset doing in the {foreach} if you want a list of 10 articles?
2) Is node 89 "below" node 66 in the content tree, iow. is node 89 a child (direct or indirect) of node 66?

The code below the {def}s should look like:

<table>
  <tr>
    <td>
      <ul>
        {foreach $news_list as $news}
          <li>{node_view_gui view=frontpagelisting content_node=$news}</li>
        {/foreach}
      </ul>
    </td>
    <td>
      <ul>
        {foreach $newsone_list as $news}
          <li>{node_view_gui view=frontpagelisting content_node=$news}</li>
        {/foreach}
      </ul>
    </td>
  </tr>
</table>

The position of the <li> tags can differ depending on what you do in the frontpagelisting view of the nodes. But that code should get you going.

Hans
http://blog.hansmelis.be

Bill Rust

Thursday 27 March 2008 8:32:27 am

Thanks for your reply Hans, I now understand that it is better coding practice to combine the {def} statements.

However, I'm still getting the same results. I had used the offset parameter because I wished to avoid pulling the first two articles, having already fetched them earlier in the cade. Apologies for leaving the max parameter in there also, that was just a matter of me testing them out and shouldn't have been there.

So, if I now remove both those parameters my results are still a mess. It seems like that instead of pulling out a maximum of 10 articles it is, in fact, looping through the array 10 times. Also results from both def statements are combined when I want them to appear separate - a list of articles from node 66 on the left-hand side and a list of articles from node 89 on the right-hand side. Nodes 66 and 89 are on the same level of the content node tree, one below the root node.

My code for the frontpagelisting is:

<li>
<a href={$node.url_alias|ezurl}>{$node.object.data_map.title.content|wash}</a>
</li>

I assume it doesn't really matter if I have my <li> in either of the templates.

Stéphane Bullier

Thursday 27 March 2008 11:54:12 am

Hello,

I think you have to use fetch "list" not fetch "tree" to displayed children :

{def $news_list=fetch( 'content', 'list', hash( 'parent_node_id', 66,
                                          'limit', 10,
                                          'sort_by', array( published, false() ) ) )

      $newsone_list=fetch( 'content', 'list', hash( 'parent_node_id', 89,
                                         'limit', 10,
                                         'sort_by', array( published, false() ) ) ) }

Good luck.

Stéphane

Maxime Thomas

Thursday 03 April 2008 11:19:18 pm

Hi,

I've seen a coma at the end of your hash table in both of your fetch.
It's maybe why you are not getting the result your fetch.

Maxime Thomas
maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou

Company Blog : http://www.wascou.org/eng/Company/Blog
Technical Blog : http://share.ez.no/blogs/maxime-thomas

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 19 2025 01:05:07
Script start
Timing: Jan 19 2025 01:05:07
Module start 'layout'
Timing: Jan 19 2025 01:05:07
Module start 'content'
Timing: Jan 19 2025 01:05:08
Module end 'content'
Timing: Jan 19 2025 01:05:08
Script end

Main resources:

Total runtime0.6828 sec
Peak memory usage4,096.0000 KB
Database Queries67

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0064 590.2656152.6094
Module start 'layout' 0.00640.0030 742.875039.4141
Module start 'content' 0.00940.6720 782.2891654.6484
Module end 'content' 0.68140.0013 1,436.937516.1875
Script end 0.6827  1,453.1250 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.4524160.0002
Check MTime0.00130.1871160.0001
Mysql Total
Database connection0.00150.220910.0015
Mysqli_queries0.622091.1013670.0093
Looping result0.00080.1174650.0000
Template Total0.645194.520.3225
Template load0.00160.236420.0008
Template processing0.643494.242220.3217
Template load and register function0.00020.024510.0002
states
state_id_array0.00090.136010.0009
state_identifier_array0.00120.171520.0006
Override
Cache load0.00140.2001340.0000
Sytem overhead
Fetch class attribute can translate value0.00070.106540.0002
Fetch class attribute name0.00130.190380.0002
XML
Image XML parsing0.00170.242840.0004
class_abstraction
Instantiating content class attribute0.00000.002480.0000
General
dbfile0.00240.3533270.0001
String conversion0.00000.001340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs