Last active
January 21, 2020 16:57
-
-
Save webinmd/930f468fdc43f3b545f31f36b7ce6683 to your computer and use it in GitHub Desktop.
Получение значений ТВ поля из всех локализаций
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $id - numeric resource id | |
// $tvname - name of tv field | |
// $tpl - template: {$value} | |
/* | |
// usage | |
{'getTvFields'|snippet:[ | |
'id' => 1, | |
'tvname' => 'slider', | |
'tpl' => 'tplTv' | |
]} | |
*/ | |
if (empty($id)) { | |
$id = $modx->resource->get('id'); | |
} | |
if (empty($tvname)) { | |
return; | |
} | |
$tpl = $modx->getOption('tpl', $scriptProperties, '@INLINE {$value}', true); | |
if (file_exists(MODX_CORE_PATH . 'components/pdotools')) { | |
$pdoTools = $modx->getService('pdoTools'); | |
} | |
if ($tv = $modx->getObject('modTemplateVar', array('name' => $tvname))){ | |
if ($tv->get('localizator_enabled')){ | |
$q = $modx->newQuery("locTemplateVarResource") | |
->where(array( | |
"contentid" => $id, | |
"tmplvarid" => $tv->get('id'), | |
)) | |
->select('value'); | |
if ($q->prepare() && $q->stmt->execute()){ | |
$tvs = $q->stmt->fetchAll(PDO::FETCH_ASSOC); | |
foreach ($tvs as $v) { | |
$output .= $pdoTools->getChunk($tpl , $v); | |
} | |
} | |
} | |
else{ | |
$output = $resource->getTVValue($field); | |
} | |
} | |
return $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment