Skip to content

Instantly share code, notes, and snippets.

@andronex
Created April 1, 2017 16:08
Show Gist options
  • Save andronex/645063b7da06094b8cce0039b53e7848 to your computer and use it in GitHub Desktop.
Save andronex/645063b7da06094b8cce0039b53e7848 to your computer and use it in GitHub Desktop.
Вывод слайдера на страницах с заполненным TV слайдера и в случае незаполненного вывод слайдов из других ресурсов.
<?php
$out = '';
if($tv = $modx->resource->getTVValue('slider-inside-oneclick')){
$tv_arr = $modx->fromJSON($tv);
if(is_array($tv_arr)){
foreach($tv_arr as $v){
if(!$v['name']) $v['name'] = $modx->resource->get('pagetitle');
$out .= $modx->parseChunk('tpl.slider-inside-oneclick', $v);
}
}
return $out;
}
else{
$res = array();
$q = $modx->newQuery('modTemplateVarResource', array('tmplvarid' => 19));
$q->select(array('modTemplateVarResource.*'));
if ($q->prepare() && $q->stmt->execute()) {
while ($row = $q->stmt->fetch(PDO::FETCH_ASSOC)) {
$res[$row['contentid']] = $row['value'];
}
if(is_array($res)){
foreach($res as $idx => $r){
$tv_arr = $modx->fromJSON($r);
foreach($tv_arr as $v){
if(!$v['name']) $v['name'] = $modx->getObject('modResource', $idx)->get('pagetitle');
$out .= $modx->parseChunk('tpl.slider-inside-oneclick', $v);
}
}
}
}
return $out;
}
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment