Skip to content

Instantly share code, notes, and snippets.

@Sentinel-7
Last active July 14, 2021 13:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save Sentinel-7/b38ab513e020628f15334dac9d343627 to your computer and use it in GitHub Desktop.
Save Sentinel-7/b38ab513e020628f15334dac9d343627 to your computer and use it in GitHub Desktop.
MIGX fenom
если у сниппета getImageList указывается id ресурса родителя &docid=`20`
{set $rows = 20 | resource : 'configurator' | fromJSON}
{foreach $rows as $row}
<h2>Конфигуратор</h2>
<h3>{$row.title}</h3>
<p>{$row.introtext}</p>
</div>
<div class="tm-firmware-panel-buttons">
<a href="{$row.zip}" class="uk-button uk-button-primary tm-icon-zip"></a>
<a href="{$row.rar}" class="uk-button uk-button-primary tm-icon-rar"></a>
</div>
</div>
<div class="tm-firmware-panel-info">
<p>{$row.info1}</p>
</div>
<div class="tm-firmware-panel-warning">
<p>{$row.info2}</p>
</div>
</div>
{/foreach}
======================================================
А как в данном варианте прописать дополнительные условия работы цикла?
Например, выводить только 2 первые записи, или пропустить первые 5 проходок?
Самое простое через ключ массива.
{*Первые два*}
{foreach $rows as $idx => $row}
{if $idx < 2}
<div>{$idx} - {$row.title}</div>
{/if}
{/foreach}
{*С пятой строки*}
{foreach $rows as $idx => $row}
{if $idx > 4}
<div>{$idx} - {$row.title}</div>
{/if}
{/foreach}
{*Чересстрочная вакханалия*}
{foreach $rows as $idx => $row}
<div{$idx is odd ? ' class="odd"' : ''>{$idx} - {$row.title} и два тикета туДаблин</div>
{/foreach}
======================================================
если нет ни одного option тогда фраза скажем «опций нет», т.е. значение по default
{set $rows = json_decode($_modx->resource.options, true)}
{if $rows?}
{foreach $rows as $row}
{if $row.active == '1'}
<option value="{$row.alt}">{$row.alt}</option>
{/if}
{/foreach}
{else}
<option value="">Вакансий нет</option>
{/if}
==============================================================
четные нечетные
{foreach $_modx->resource.design_list | fromJSON as $idx => $item}
{if $idx is odd}
....
{/if}
{if $idx is even} // четные
...
{/if}
{/foreach}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment