Page 1 of 1
Help with News Module Template Section Loop
Posted: Mon Jul 07, 2014 7:17 pm
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>
Re: Help with News Module Template Section Loop
Posted: Mon Jul 07, 2014 7:28 pm
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>
Re: Help with News Module Template Section Loop
Posted: Mon Jul 07, 2014 7:37 pm
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?
Re: Help with News Module Template Section Loop
Posted: Mon Jul 07, 2014 7:46 pm
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...
Re: Help with News Module Template Section Loop
Posted: Tue Jul 08, 2014 5:08 am
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?
Re: Help with News Module Template Section Loop
Posted: Tue Jul 08, 2014 11:06 am
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...
Re: Help with News Module Template Section Loop
Posted: Tue Jul 08, 2014 9:40 pm
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.
Re: Help with News Module Template Section Loop
Posted: Tue Jul 08, 2014 9:46 pm
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.