Yaz*_*min 2 expressionengine switch-statement
我有一些代码创建一个表,根据条目的行值交替行颜色.
<table class="authorList" cellspacing="0">
{exp:channel:entries channel="team" disable="categories|member_data|pagination" orderby="team-last-name" sort="asc"}
{if team-not-with-us != 'y'}
<tr class="{switch="odd|even"} authorInfo">
<th class="authorName">
{if team-bio != ''}<a href="{site_url}about/the-team/{url_title}">{/if}
{title}
{if team-bio != ''}</a>{/if}
</th>
<td class="position">{team-position}</td>
</tr>
{/if}
{/exp:channel:entries}
</table>
Run Code Online (Sandbox Code Playgroud)
问题是当我删除一个条目时,我最终连续两个奇数或两个偶数,留下两个相同颜色的行并排.
虽然切换功能很方便,但它引用了数据库中的行数.我不相信我可以应用它来引用if语句中的实际行计数来解决我的问题.(如我错了请纠正我.)
我知道如何使用php进行此更改:
<?php $oddevenrow = 0; ?>
{if team-not-with-us != 'y'}
<?php $oddevenrow++; ?>
<?php ($oddeven = ($oddevenrow % 2 ? 'odd' : 'even')); ?>
<tr class="<?php echo $oddeven; ?> authorInfo">
Run Code Online (Sandbox Code Playgroud)
但我不允许在EE安装中打开PHP.
在EE中我能做些类似的事吗?
谢谢!
你正在寻找开关标签.
{开关= "奇|偶数"}
但看起来你已经知道了.看起来你需要变量团队 - 而不是我们!='y'.因为在结果返回后你正在进行验证,所以你会在彼此相邻的多个奇数或偶数行结束.避免这种情况的简单方法是使用channel:entries搜索参数.示例:search:team-not-with-us ="not y"
<table class="authorList" cellspacing="0">
{exp:channel:entries
channel="team"
disable="categories|member_data|pagination"
orderby="team-last-name"
sort="asc"
search:team-not-with-us="not y"
}
<tr class="{switch="odd|even"} authorInfo">
<th class="authorName">
{if team-bio != ''}<a href="{site_url}about/the-team/{url_title}">{/if}
{title}
{if team-bio != ''}</a>{/if}
</th>
<td class="position">{team-position}</td>
</tr>
{/exp:channel:entries}
</table>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1495 次 |
| 最近记录: |