Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 使用内部行Smarty列替代内部列_Sorting_Foreach_Smarty_Rows - Fatal编程技术网

Sorting 使用内部行Smarty列替代内部列

Sorting 使用内部行Smarty列替代内部列,sorting,foreach,smarty,rows,Sorting,Foreach,Smarty,Rows,我在一个表中有3列,我的信息显示正确。但是,该信息在smarty模板中水平显示。 1 2 3 4.56 7 8 9 如何将其垂直显示 像这样: 14.7 2.5.8 369 我需要的是一个解决方案,类似于: {html_table inner=rows cols=3 loop=$array} {* Categories *} {if !empty($categs)} {if !empty($category.ID)} <h3>{l}Books{/l}</h3> {/if

我在一个表中有3列,我的信息显示正确。但是,该信息在smarty模板中水平显示。
1 2 3
4.56
7 8 9

如何将其垂直显示

像这样:
14.7
2.5.8
369

我需要的是一个解决方案,类似于: {html_table inner=rows cols=3 loop=$array}

{* Categories *}
{if !empty($categs)}
{if !empty($category.ID)}
<h3>{l}Books{/l}</h3>
{/if}
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
{foreach from=$categs item=cat name=categs}
{if ($smarty.foreach.categs.iteration mod $cats_per_col eq 1 and $cats_per_col gt 1) or    $smarty.foreach.categs.first}<td>{/if}
<h2 {if !empty($category.ID)}class="blocktext"{/if}><a href="{if !empty($cat.URL)}    {$cat.URL}{else}{$smarty.const.DOC_ROOT}/{$cat.CACHE_URL|escape}{/if}" {if $cat.NEW_WINDOW eq 1}target="blank"{/if}  title="{$cat.TITLE|escape}" class="catHomeMain">{$cat.TITLE|escape} </a>{if $smarty.const.CATS_COUNT}{if !empty($cat.URL)}{else} <span class="catHomeCount">({$cat.COUNT})</span>{/if}{/if}</h2>
{* Display subcategories *}
{if !empty($cat.SUBCATS)}
{foreach from=$cat.SUBCATS item=scat name=scategs key=key}
{capture name="column"}{math equation="x % 3" x=$key}{/capture}
{if $smarty.capture.column == "0"}
<table border="0" cellpadding="0" cellspacing="0">
<tr>
    <td width="177px">
<ul class="navcontainer"><li>
    <a href="{if !empty($scat.URL)}{$scat.URL}{else}   {$smarty.const.DOC_ROOT}/{$scat.CACHE_URL|escape}{/if}" {if $scat.NEW_WINDOW eq 1}target="blank"{/if}  title="{$scat.TITLE|escape}" class="catHomeSub">{$scat.TITLE|escape}</a></li></ul>
            </td>
{elseif  $smarty.capture.column == "1"}
    <td width="177px">
<ul class="navcontainer"><li>
<a href="{if !empty($scat.URL)}{$scat.URL}{else}  {$smarty.const.DOC_ROOT}/{$scat.CACHE_URL|escape}{/if}" {if $scat.NEW_WINDOW eq 1}target="blank"{/if}  title="{$scat.TITLE|escape}" class="catHomeSub">{$scat.TITLE|escape}</a>
</li></ul>
    </td>
{elseif $smarty.capture.column == "2"}
    <td width="177px">
<ul class="navcontainer"><li>
<a href="{if !empty($scat.URL)}{$scat.URL}{else}  {$smarty.const.DOC_ROOT}/{$scat.CACHE_URL|escape}{/if}" {if $scat.NEW_WINDOW eq 1}target="blank"{/if}  title="{$scat.TITLE|escape}" class="catHomeSub">{$scat.TITLE|escape}</a>
</li></ul>
    </td>
</tr>
</table>
{/if}
{/foreach}

{if $smarty.capture.column != 2}
<!-- Close the table! -->
</tr></table>
{/if}
{/if}
{if ($smarty.foreach.categs.iteration mod $cats_per_col eq 0 and $cats_per_col gt 1) or $smarty.foreach.categs.last}</td>{/if}
{/foreach}
</tr>
</table>
<div class="break" style="height:20px;"></div>
{/if}
{*Categories*}
{if!空($categs)}
{if!空($category.ID)}
{l} 书籍{/l}
{/if}
{foreach from=$categs item=cat name=categs}
{if($smarty.foreach.categs.iteration mod$cats_per_col eq 1和$cats_per_col gt 1)或$smarty.foreach.categs.first}{/if}
{if$smarty.const.CATS_COUNT}{if!empty($cat.URL)}{else}({$cat.COUNT}){/if}{/if}
{*显示子类别*}
{if!空($cat.SUBCATS)}
{foreach from=$cat.SUBCATS item=scat name=scategs key=key}
{capture name=“column”}{math equation=“x%3”x=$key}{/capture}
{如果$smarty.capture.column==“0”}
{elseif$smarty.capture.column==“1”}
{elseif$smarty.capture.column==“2”}
{/if} {/foreach} {如果$smarty.capture.column!=2} {/if} {/if} {if($smarty.foreach.categs.iteration mod$cats_per_col eq 0和$cats_per_col gt 1)或$smarty.foreach.categs.last}{/if} {/foreach} {/if}
以下是我所做的:

首先,我在PHP文件中创建了一个数组:

$tpl->assign('old', array('item1','item3','item5','item2','item4','item6'));
然后在.TPL文件中,我重写了如下代码:

{if $cat.TITLE == "Old Books"}

<table> 

<tr> 

{section name=nr loop=$old} 

<td style="width:177px;">

<ul class="navcontainer"><li>

<a href="{$smarty.const.DOC_ROOT}/{$old[nr]}/" title="{$old[nr]|replace:'_':' '|escape}" class="catHomeSub">{$old[nr]|replace:'_':' '|escape}</a></li></ul></td> 

{if $smarty.section.nr.iteration % 3 == 0} 

</tr> 

<tr> 

{/if} 

{/section} 

</tr> 

</table>
{if$cat.TITLE==“旧书”}
{section name=nr loop=$old}
{如果$smarty.section.nr.iteration%3==0} {/if} {/section}
这将输出垂直“排序”的3列数据

第1项第3项第5项
项目2项目4项目6