Forums / Setup & design / Fetching confusion

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

eZ debug

Timing: Jan 19 2025 02:35:57
Script start
Timing: Jan 19 2025 02:35:57
Module start 'content'
Timing: Jan 19 2025 02:35:57
Module end 'content'
Timing: Jan 19 2025 02:35:57
Script end

Main resources:

Total runtime0.2138 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0067 588.8516180.8438
Module start 'content' 0.00670.0047 769.6953101.9609
Module end 'content' 0.01140.2023 871.6563531.2500
Script end 0.2137  1,402.9063 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00391.8103200.0002
Check MTime0.00150.7182200.0001
Mysql Total
Database connection0.00080.365010.0008
Mysqli_queries0.169379.18121410.0012
Looping result0.00140.64301390.0000
Template Total0.201994.410.2019
Template load0.00090.410710.0009
Template processing0.201094.026810.2010
Override
Cache load0.00060.278410.0006
Sytem overhead
Fetch class attribute can translate value0.00100.487010.0010
XML
Image XML parsing0.00020.102110.0002
General
dbfile0.00180.8565200.0001
String conversion0.00000.002530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

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

Time used to render debug report: 0.0001 secs