Forums / Setup & design / loop the object

loop the object

Author Message

M M

Monday 27 December 2004 6:49:13 am

Hi,

Sorry All solutions you're giving me till now is concerned with the objects that are entered while { loop= integer } not

To understand what i mean try to give a cell a bgcolor or anything to specify it , then when you

<table>
{section name=loop loop=6}
<tr>
<td bgcolor= red>
try it even without fetching to any data from the content
if u use {$:item.name} as an example it won't be displayed but the background will
</td>
</tr>
{/section}
</table>

This will display the row repeated for six times not depending on the object i'm fetching , while the normal way we use is

<table>
{section name=Child loop=fetch('content','list', hash('parent_node_id',69))}
<tr>
<td bgcolor=red> {$:item.name} </td>
</tr>
{/section}

</table>

The previous will display rows depending on the number of children objects even if i use max [needs at least 6 to do what i want] or limit [ which is nearly gives the same result as max]

So what i really need is to merge these 2 cases meaning that i can fetch the data i need from a specific node while setting the no of looping [ due to designing issues]

I hope I could let you understand my point of view

Thanks in advance

Tobias Persson

Monday 27 December 2004 7:14:50 am

I combined your examples above. And some math functions.
I think this might solve your problem.

{let loops=6 countitems=0}

<table>
{section  loop=fetch('content','list', hash('parent_node_id',71, limit, 6))}
{set countitems=fetch('content','list_count', hash('parent_node_id',71))}
<tr>
<td bgcolor=red> {$:item.name} </td>
</tr>
{/section}
</table>

{set loops=$loops|sub($countitems)}

{section $loops|gt(0)}
<table>
{section name=loop loop=$loops}
<tr>
<td bgcolor= red> 
try it even without fetching to any data from the content
</td>
</tr>
{/section}
</table>
{/section}

{/let}

M M

Monday 27 December 2004 9:11:03 am

May be i can't understand what you send to me but to the extent i understood the result that i've seen was 20 rows displayed without fetching to any data

So if you can describe what u mean once more please do

Thanks in advance

Tobias Persson

Monday 27 December 2004 10:02:57 am

Opps. I forgot a 'show' in the section. I also moved some variables into the 'let' . Remember to change the p_node_id to the correct value.

Here is the more correct code:

{let loops=6 countitems=0 p_node_id=93}

<table>
{section  loop=fetch('content','list', hash('parent_node_id',$p_node_id, limit, $loops))}
{set countitems=fetch('content','list_count', hash('parent_node_id',$p_node_id))}
<tr>
<td bgcolor=red> {$:item.name} </td>
</tr>
{/section}
</table>

{set loops=$loops|sub($countitems)}

{section show=$loops|gt(0)}
<table>
{section name=loop loop=$loops}
<tr>
<td bgcolor= red> 
try it even without fetching to any data from the content
</td>
</tr>
{/section}
</table>
{/section}

{/let}

M M

Tuesday 28 December 2004 3:41:06 am

Hello

How are you to day? I hope that everything is fine..

I'm sorry to tell you that there is still a problem .By adding the last code you sent to me, the name of the object didn't appear and the background for the cell appears only twice which means that the loop was done only 2 times

Moreover I don't understand why are you writing the code around two different tables, anyway i need it the loop on only one row in one table not more.

Thanks for your attention

Tobias Persson

Tuesday 28 December 2004 4:14:28 am

Hmmm. That was strange. What version of EZ are you using?
I have tried the code both in 3.4 and 3.5.

The code is pretty simple, so it should work. It works like this:

* fetch all but max 6 objects from $p_node_id.
* fetch the no of objects under $p_node_id (and set variable $countitems to this value)
* loop the objects
* calculate the remaining rows by ($loops = 6 - $countitems)
* If loops > 0 then loop $loops times

And about the two tables. I just copied the code you pasted for them, so thats why they are there. Just remove the </table> and <table> in the middle and you will get it in one table.

M M

Tuesday 28 December 2004 5:03:36 am

Would you please resend to me the code you've tried but applied on only one table including one row and one cell

I don't know may be i wrote it with something missing

Thanks in advance

Tobias Persson

Tuesday 28 December 2004 5:21:40 am

Oki.

{let loops=6 countitems=0 p_node_id=72}

<table>
{section  loop=fetch('content','list', hash('parent_node_id',$p_node_id, limit, $loops))}
{set countitems=fetch('content','list_count', hash('parent_node_id',$p_node_id))}
<tr>
<td bgcolor=red> {$:item.name} </td>
</tr>
{/section}

{set loops=$loops|sub($countitems)}

{section show=$loops|gt(0)}
{section name=loop loop=$loops}
<tr>
<td bgcolor= red> 
try it even without fetching to any data from the content
</td>
</tr>
{/section}

{/section}
</table>
{/let}

I have inserted the code inte 3.5 EZ demo at devel.ezpublish.no

You can see it at the top, right now (will be deleted when ez reset the demo) at: http://devel.ezpublish.no/products/black_box

and the template is over at:
http://admindevel.ezpublish.no/visual/templateedit/design/news/override/templates/full/product.tpl

M M

Tuesday 28 December 2004 8:24:48 am

Wow It works :)))

Thanks so so so much