Created
February 26, 2020 11:21
-
-
Save andronex/81fc8a82de0870340f5d6a424e964e03 to your computer and use it in GitHub Desktop.
Замена шаблона ресурса MODX налету в зависимости от авторизации пользователя или любых прочий условий
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 | |
$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