Help with News Module Template Section Loop

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
cpansewicz
Forum Members
Forum Members
Posts: 142
Joined: Fri Jun 17, 2011 12:22 am

Help with News Module Template Section Loop

Post by cpansewicz »

Hi,

I am working on a template for the News Module. I've tried a few solutions but couldn't get the the loop right. I have several custom fields in the News Module: row1, row2, row3, row4, etc. I would like the rows to alternate css class, even odd, etc.

I appreciate any help with this! I know it is probably straight forward, and I am just missing something.

This is the code that I am working on:

<table>
{section name=row loop=$rows start=1 step=1}

{if isset($items[0]->fieldsbyname.row{$rows[row]})}
<tr>
<td align="left" valign="top" class="{cycle values="odd,even"}">
{$entry->fieldsbyname.row{$rows[row]}->value}
</td>
</tr>
{/if}

{/section}
</table>
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: Help with News Module Template Section Loop

Post by Jo Morg »

http://www.smarty.net/docs/en/language. ... .cycle.tpl
HTH ;)

ps: actually the if logic may be messing it up...

try:

Code: Select all

<table>
{section name=row loop=$rows start=1 step=1}
{if !isset($items[0]->fieldsbyname.row{$rows[row]})}
{continue}
{/if}
<tr>
<td align="left" valign="top" class="{cycle values="odd,even"}">
{$entry->fieldsbyname.row{$rows[row]}->value}
</td>
</tr>
{/section}
</table>
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
cpansewicz
Forum Members
Forum Members
Posts: 142
Joined: Fri Jun 17, 2011 12:22 am

Re: Help with News Module Template Section Loop

Post by cpansewicz »

Thank you! I think I have the cycle part of my code right. What is causing an error is the {section}, and then calling in the custom fields into the table. My custom field names are "row1", "row2", "row3", etc/ How do I accomplish that in the loop?
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: Help with News Module Template Section Loop

Post by Jo Morg »

Code: Select all

{$entry->fieldsbyname.row[$smarty.section.row.index]->value}
You probably need to change some of the names (vars or others) otherwise it will get confusing.... and those {} you had were wrong...
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
cpansewicz
Forum Members
Forum Members
Posts: 142
Joined: Fri Jun 17, 2011 12:22 am

Re: Help with News Module Template Section Loop

Post by cpansewicz »

Thank you. Let me work with this. The template isn't calling in the custom field information, but it may be an issue with something else.

Should I use {foreach} instead of {section} for a news module template?
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: Help with News Module Template Section Loop

Post by Jo Morg »

cpansewicz wrote:The template isn't calling in the custom field information (...)
TBH, I didn't check that particular syntax... Please search the forum as this has been answered a number of times, or refer to the sample templates, as they have examples on how to call custom fields directly...
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
cpansewicz
Forum Members
Forum Members
Posts: 142
Joined: Fri Jun 17, 2011 12:22 am

Re: Help with News Module Template Section Loop

Post by cpansewicz »

Please forgive me. I am new to writing smarty code. I have really done my due diligence in searching the forum for suggestions on loops in a table before I posted my question. Also, there is nothing in the News Module help that discusses what format to use for custom fields as well.

I will work on the suggestions posted above. I think I have another non-related issue though that I have to work out, before I can work on this template.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: Help with News Module Template Section Loop

Post by Jo Morg »

cpansewicz wrote:Also, there is nothing in the News Module help that discusses what format to use for custom fields as well.
No, indeed not. But I meant in the news sample templates. IIRC its is well documented in the code comments inside the templates.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Post Reply

Return to “Modules/Add-Ons”