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
[email protected] | 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.