Skip to content

Instantly share code, notes, and snippets.

@andronex
Created February 26, 2020 11:21
Show Gist options
  • Save andronex/81fc8a82de0870340f5d6a424e964e03 to your computer and use it in GitHub Desktop.
Save andronex/81fc8a82de0870340f5d6a424e964e03 to your computer and use it in GitHub Desktop.
Замена шаблона ресурса MODX налету в зависимости от авторизации пользователя или любых прочий условий
<?php
$is_admin = false;
switch ($modx->event->name) {
case 'OnWebPageInit':
if($modx->user->isAuthenticated('web')){
$is_admin = true;
}
if ($is_admin) {
//Устанавливаем ключ для кэша версии для админа
$modx->setOption('cache_resource_key', 'resource/is_admin');
}
break;
case 'OnLoadWebDocument':
$id = $modx->resource->get('id');
$template_old = $modx->resource->get('template');
if($template_old == 1){
//$resource = $modx->getObject('modResource', $id);
$template = 13;
if($modx->user->isAuthenticated('web')){
$is_admin = true;
}
if ($is_admin) {
$modx->resource->set('template', $template);
}
}
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment