Александр Христич 11 Posted February 10 Report Share Posted February 10 Использую код для вывода картинок в анонсах из постов/тем в Страницах: entry и recordRow / и Форумах: topicRow и topicRowSnnipet. {{$location = $record != NULL ? $record : ($row->post != NULL ? $row->post : $row);}} {{$field_content = $row->post == NULL ? 'field_'.$location->database()->field_content : $row->post; $field_content = $row->post == NULL ? $location->$field_content : $field_content;}} {{if \preg_match( '#<fileStore.core_Attachment>\S+(?:jpg|jpeg|png|webp)#', $field_content, $image_url )}} {{$image_url = \str_replace('<fileStore.core_Attachment>', \IPS\File::getClass('core_Attachment')->baseUrl(), $image_url[0]);}} {{if settings.lazy_load_enabled}} <a href="{$record->url( "getPrefComment" )}" title="{lang="read_more_about" sprintf="$record->_title"}" > <img class='ipsImage' src='{expression="\IPS\Text\Parser::blankImage()"}' alt='{wordbreak="$record->_title"}' data-src='{file="$image_url" extension="core_Attachment"}'> </a> {{else}} <a href="{$record->url( "getPrefComment" )}" title="{lang="read_more_about" sprintf="$record->_title"}" > <img class='ipsImage' alt='{wordbreak="$record->_title"}' src='{file="$image_url" extension="core_Attachment"}'> </a> {{endif}} {{endif}} меняя в зависимости от шаблонов $record на $row. Понадобилось то же самое сделать в пользовательских блоках. В Страницах создал шаблон блока Последние темы код шаблона {{foreach $topics as $topic}} {template="row" group="global" app="forums" location="front" params="NULL, NULL, $topic, FALSE"} {{endforeach}} В row.html вставляю в нужном месте код вывода картинки и вылетает ошибка. Ошибку вызывает именно {{$location = $row != NULL ? $row : ($row->post != NULL ? $row->post : $row);}} {{$field_content = $row->post == NULL ? 'field_'.$location->database()->field_content : $row->post; $field_content = $row->post == NULL ? $location->$field_content : $field_content;}} Уважаемый Кирилл,помогите разобраться,пожалуйста,как этот код использовать в шаблоне блока Последние темы. Обратиться Quote Link to comment Share on other sites More sharing options...
Кирилл 183 Posted February 10 Report Share Posted February 10 Какая ошибка? Обратиться Quote Link to comment Share on other sites More sharing options...
Александр Христич 11 Posted February 11 Author Report Share Posted February 11 Кирилл [[Template forums/front/global/row is throwing an error. This theme may be out of date. Run the support tool in the AdminCP to restore the default theme.]] Обратиться Quote Link to comment Share on other sites More sharing options...
Александр Христич 11 Posted February 11 Author Report Share Posted February 11 (edited) Кирилл Полный код который вставляю {{$location = $row != NULL ? $row : ($row->post != NULL ? $row->post : $row);}} {{$field_content = $row->post == NULL ? 'field_'.$location->database()->field_content : $row->post; $field_content = $row->post == NULL ? $location->$field_content : $field_content;}} {{if \preg_match( '#<fileStore.core_Attachment>\S+(?:jpg|jpeg|png|webp)#', $field_content, $image_url )}} {{if settings.lazy_load_enabled}} <a href="{$topic->url( "getPrefComment" )}" title="{lang="read_more_about" sprintf="$topic->_title"}" > <img class='ipsImage' src='{expression="\IPS\Text\Parser::blankImage()"}' alt='{wordbreak="$topic->_title"}' data-src='{file="$image_url" extension="core_Attachment"}'></a> {{else}} <a href="{$topic->url( "getPrefComment" )}" title="{lang="read_more_about" sprintf="$topic->_title"}" > <img class='ipsImage' alt='{wordbreak="$topic->_title"}' src='{file="$image_url" extension="core_Attachment"}'></a> {{endif}} {{endif}} Кирилл В topicRow код {{$location = $row != NULL ? $row : ($row->post != NULL ? $row->post : $row);}} {{$field_content = $row->post == NULL ? 'field_'.$location->database()->field_content : $row->post; $field_content = $row->post == NULL ? $location->$field_content : $field_content;}} {{if \preg_match( '#<fileStore.core_Attachment>\S+(?:jpg|jpeg|png|webp)#', $field_content, $image_url )}} {{$image_url = \str_replace('<fileStore.core_Attachment>', \IPS\File::getClass('core_Attachment')->baseUrl(), $image_url[0]);}} {{if settings.lazy_load_enabled}} <a href="{$row->url( "getPrefComment" )}" title="{lang="read_more_about" sprintf="$row->_title"}" > <img class='ipsImage' src='{expression="\IPS\Text\Parser::blankImage()"}' alt='{wordbreak="$row->_title"}' data-src='{file="$image_url" extension="core_Attachment"}'></a> {{else}} <a href="{$row->url( "getPrefComment" )}" title="{lang="read_more_about" sprintf="$row->_title"}" > <img class='ipsImage' alt='{wordbreak="$row->_title"}' src='{file="$image_url" extension="core_Attachment"}'></a> {{endif}} {{endif}} Edited February 11 by Александр Христич Обратиться Quote Link to comment Share on other sites More sharing options...
Кирилл 183 Posted February 11 Report Share Posted February 11 2 часа назад, Александр Христич сказал: Кирилл [[Template forums/front/global/row is throwing an error. This theme may be out of date. Run the support tool in the AdminCP to restore the default theme.]] Описание такой ошибки обычно есть в логах в Поддержке. Обратиться Quote Link to comment Share on other sites More sharing options...
Александр Христич 11 Posted February 11 Author Report Share Posted February 11 Кирилл Error: Call to a member function database() on null in /home/hristich/web/site.ru/public_html/system/Theme/Theme.php(880) : eval()'d code:1200 Stack trace: #0 /home/hristich/web/site.ru/public_html/system/Theme/SandboxedTemplate.php(61): IPS\Theme\class_forums_front_global->row() #1 /home/hristich/web/site.ru/public_html/applications/cms/sources/Theme/Theme.php(610) : eval()'d code(24): IPS\Theme\_SandboxedTemplate->__call() #2 /home/hristich/web/site.ru/public_html/applications/cms/sources/Blocks/Block.php(280): IPS\Theme\class_cms_block_topicFeed->anons() #3 /home/hristich/web/site.ru/public_html/system/Widget/Widget.php(234): IPS\cms\Blocks\_Block->getTemplate() #4 /home/hristich/web/site.ru/public_html/system/Content/Widget.php(522): IPS\_Widget->output() #5 /home/hristich/web/site.ru/public_html/applications/cms/sources/Blocks/Block.php(242): IPS\Content\_Widget->render() #6 /home/hristich/web/site.ru/public_html/applications/cms/widgets/Blocks.php(143): IPS\cms\Blocks\_Block::display() #7 /home/hristich/web/site.ru/public_html/system/Widget/Widget.php(833): IPS\cms\widgets\_Blocks->render() #8 /home/hristich/web/site.ru/public_html/system/Widget/Widget.php(888): IPS\_Widget->_render() #9 /home/hristich/web/site.ru/public_html/system/Theme/Theme.php(880) : eval()'d code(18575): IPS\_Widget->__toString() #10 /home/hristich/web/site.ru/public_html/system/Theme/SandboxedTemplate.php(61): IPS\Theme\class_core_front_global->widgetContainer() #11 /home/hristich/web/site.ru/public_html/system/Theme/Theme.php(880) : eval()'d code(6781): IPS\Theme\_SandboxedTemplate->__call() #12 /home/hristich/web/site.ru/public_html/system/Theme/SandboxedTemplate.php(61): IPS\Theme\class_core_front_global->globalTemplate() #13 /home/hristich/web/site.ru/public_html/system/Dispatcher/Dispatcher.php(173): IPS\Theme\_SandboxedTemplate->__call() #14 /home/hristich/web/site.ru/public_html/system/Dispatcher/Standard.php(113): IPS\_Dispatcher->finish() #15 /home/hristich/web/site.ru/public_html/system/Dispatcher/Front.php(619): IPS\Dispatcher\_Standard->finish() #16 /home/hristich/web/site.ru/public_html/system/Dispatcher/Dispatcher.php(155): IPS\Dispatcher\_Front->finish() #17 /home/hristich/web/site.ru/public_html/index.php(13): IPS\_Dispatcher->run() #18 {main} ОБРАТНАЯ ТРАССИРОВКА #0 /home/hristich/web/site.ru/public_html/system/Theme/SandboxedTemplate.php(71): IPS\_Log::log() #1 /home/hristich/web/site.ru/public_html/applications/cms/sources/Theme/Theme.php(610) : eval()'d code(24): IPS\Theme\_SandboxedTemplate->__call() #2 /home/hristich/web/site.ru/public_html/applications/cms/sources/Blocks/Block.php(280): IPS\Theme\class_cms_block_topicFeed->anons() #3 /home/hristich/web/site.ru/public_html/system/Widget/Widget.php(234): IPS\cms\Blocks\_Block->getTemplate() #4 /home/hristich/web/site.ru/public_html/system/Content/Widget.php(522): IPS\_Widget->output() #5 /home/hristich/web/site.ru/public_html/applications/cms/sources/Blocks/Block.php(242): IPS\Content\_Widget->render() #6 /home/hristich/web/site.ru/public_html/applications/cms/widgets/Blocks.php(143): IPS\cms\Blocks\_Block::display() #7 /home/hristich/web/site.ru/public_html/system/Widget/Widget.php(833): IPS\cms\widgets\_Blocks->render() #8 /home/hristich/web/site.ru/public_html/system/Widget/Widget.php(888): IPS\_Widget->_render() #9 /home/hristich/web/site.ru/public_html/system/Theme/Theme.php(880) : eval()'d code(18575): IPS\_Widget->__toString() #10 /home/hristich/web/site.ru/public_html/system/Theme/SandboxedTemplate.php(61): IPS\Theme\class_core_front_global->widgetContainer() #11 /home/hristich/web/site.ru/public_html/system/Theme/Theme.php(880) : eval()'d code(6781): IPS\Theme\_SandboxedTemplate->__call() #12 /home/hristich/web/site.ru/public_html/system/Theme/SandboxedTemplate.php(61): IPS\Theme\class_core_front_global->globalTemplate() #13 /home/hristich/web/site.ru/public_html/system/Dispatcher/Dispatcher.php(173): IPS\Theme\_SandboxedTemplate->__call() #14 /home/hristich/web/site.ru/public_html/system/Dispatcher/Standard.php(113): IPS\_Dispatcher->finish() #15 /home/hristich/web/site.ru/public_html/system/Dispatcher/Front.php(619): IPS\Dispatcher\_Standard->finish() #16 /home/hristich/web/site.ru/public_html/system/Dispatcher/Dispatcher.php(155): IPS\Dispatcher\_Front->finish() #17 /home/hristich/web/site.ru/public_html/index.php(13): IPS\_Dispatcher->run() #18 {main} Обратиться Quote Link to comment Share on other sites More sharing options...
Александр Христич 11 Posted February 11 Author Report Share Posted February 11 (edited) Сделал такой вывод тем форума (на будущем сайте будет использоваться только одна категория форумов) Спойлер Здесь используется только шаблон topicRow и картинка выводится с помощью этого кода Спойлер {{$location = $row != NULL ? $row : ($row->post != NULL ? $row->post : $row);}} {{$field_content = $row->post == NULL ? 'field_'.$location->database()->field_content : $row->post; $field_content = $row->post == NULL ? $location->$field_content : $field_content;}} {{if \preg_match( '#<fileStore.core_Attachment>\S+(?:jpg|jpeg|png|webp)#', $field_content, $image_url )}} {{$image_url = \str_replace('<fileStore.core_Attachment>', \IPS\File::getClass('core_Attachment')->baseUrl(), $image_url[0]);}} {{if settings.lazy_load_enabled}} <a href="{$row->url( "getPrefComment" )}" title="{lang="read_more_about" sprintf="$row->_title"}" > <img class='ipsImage' src='{expression="\IPS\Text\Parser::blankImage()"}' alt='{wordbreak="$row->_title"}' data-src='{file="$image_url" extension="core_Attachment"}'></a> {{else}} <a href="{$row->url( "getPrefComment" )}" title="{lang="read_more_about" sprintf="$row->_title"}" > <img class='ipsImage' alt='{wordbreak="$row->_title"}' src='{file="$image_url" extension="core_Attachment"}'></a> {{endif}} {{endif}} Возникла проблема при использовании этого кода в шаблоне forums->front->global->row.html Edited February 11 by Александр Христич Обратиться Quote Link to comment Share on other sites More sharing options...
Кирилл 183 Posted February 11 Report Share Posted February 11 Перед использованием $location, нужно проверить наличие: if isset( $location ) Обратиться Quote Link to comment Share on other sites More sharing options...
Александр Христич 11 Posted February 11 Author Report Share Posted February 11 19 минут назад, Кирилл сказал: Перед использованием $location, нужно проверить наличие: if isset( $location ) это как? Обратиться Quote Link to comment Share on other sites More sharing options...
Кирилл 183 Posted February 12 Report Share Posted February 12 {{$location = $row != NULL ? $row : ($row->post != NULL ? $row->post : $row);}} {{if $location}} {{$field_content = $row->post == NULL ? 'field_'.$location->database()->field_content : $row->post; $field_content = $row->post == NULL ? $location->$field_content : $field_content;}} {{if \preg_match( '#<fileStore.core_Attachment>\S+(?:jpg|jpeg|png|webp)#', $field_content, $image_url )}} {{$image_url = \str_replace('<fileStore.core_Attachment>', \IPS\File::getClass('core_Attachment')->baseUrl(), $image_url[0]);}} {{if settings.lazy_load_enabled}} <a href="{$row->url( "getPrefComment" )}" title="{lang="read_more_about" sprintf="$row->_title"}" > <img class='ipsImage' src='{expression="\IPS\Text\Parser::blankImage()"}' alt='{wordbreak="$row->_title"}' data-src='{file="$image_url" extension="core_Attachment"}'></a> {{else}} <a href="{$row->url( "getPrefComment" )}" title="{lang="read_more_about" sprintf="$row->_title"}" > <img class='ipsImage' alt='{wordbreak="$row->_title"}' src='{file="$image_url" extension="core_Attachment"}'></a> {{endif}} {{endif}} {{endif}} Обратиться Quote Link to comment Share on other sites More sharing options...
Александр Христич 11 Posted February 16 Author Report Share Posted February 16 Кирилл к сожалению ничего так и не работает. Пробывал добавить переменную $rows в шаблон forums->front->global->row.html, без результатов. Практически уверен что ошибку выдает строка {{$field_content = $row->post == NULL ? 'field_'.$location->database()->field_content : $row->post; $field_content = $row->post == NULL ? $location->$field_content : $field_content;}} потому что если ее убрать из всего когда ,то ошибок нет. И почему в в Страницах: entry и recordRow / и Форумах: topicRow и topicRowSnnipet все работает как надо,а вот в forums->front->global->row.html не хочет хоть ты тресни. Обратиться Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.