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>
Help with News Module Template Section Loop
-
cpansewicz
- Forum Members

- Posts: 142
- Joined: Fri Jun 17, 2011 12:22 am
Re: Help with News Module Template Section Loop
http://www.smarty.net/docs/en/language. ... .cycle.tpl
HTH
ps: actually the if logic may be messing it up...
try:
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!
* 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

- Posts: 142
- Joined: Fri Jun 17, 2011 12:22 am
Re: Help with News Module Template Section Loop
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?
Re: Help with News Module Template Section Loop
Code: Select all
{$entry->fieldsbyname.row[$smarty.section.row.index]->value}
"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!
* 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

- Posts: 142
- Joined: Fri Jun 17, 2011 12:22 am
Re: Help with News Module Template Section Loop
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?
Should I use {foreach} instead of {section} for a news module template?
Re: Help with News Module Template Section Loop
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...cpansewicz wrote:The template isn't calling in the custom field information (...)
"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!
* 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

- Posts: 142
- Joined: Fri Jun 17, 2011 12:22 am
Re: Help with News Module Template Section Loop
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.
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.
Re: Help with News Module Template Section Loop
No, indeed not. But I meant in the news sample templates. IIRC its is well documented in the code comments inside the templates.cpansewicz wrote:Also, there is nothing in the News Module help that discusses what format to use for custom fields as well.
"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!
* 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!

