Перейти к содержанию

Адаптация кода.


 Поделиться

Рекомендуемые сообщения

Использую код для вывода картинок в анонсах из постов/тем  в Страницах: 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;}}

Уважаемый Кирилл,помогите разобраться,пожалуйста,как этот код использовать в шаблоне  блока  Последние темы.

Ссылка на комментарий
Поделиться на другие сайты

Кирилл 

[[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.]]

Ссылка на комментарий
Поделиться на другие сайты

Кирилл Полный код который вставляю

{{$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}}
Изменено пользователем Александр Христич
Ссылка на комментарий
Поделиться на другие сайты
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.]]

Описание такой ошибки обычно есть в логах в Поддержке.

Ссылка на комментарий
Поделиться на другие сайты

Кирилл 

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}

 

Ссылка на комментарий
Поделиться на другие сайты

Сделал такой вывод тем форума (на будущем сайте будет использоваться только одна категория форумов)

Спойлер

942781768_2023-02-1114-14-05.thumb.png.228639d4c6006a21fdf58bca3df1ddf7.png

Здесь используется только шаблон 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

Изменено пользователем Александр Христич
Ссылка на комментарий
Поделиться на другие сайты

Перед использованием $location, нужно проверить наличие: if isset( $location )

Ссылка на комментарий
Поделиться на другие сайты
19 минут назад, Кирилл сказал:

Перед использованием $location, нужно проверить наличие: if isset( $location )

это как?

Ссылка на комментарий
Поделиться на другие сайты
{{$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}}

 

Ссылка на комментарий
Поделиться на другие сайты

Кирилл к сожалению ничего так и не работает.

Пробывал добавить переменную $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 не хочет хоть ты тресни.

 

Ссылка на комментарий
Поделиться на другие сайты

Присоединяйтесь к обсуждению

Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.

Гость
Ответить в этой теме...

×   Вставлено с форматированием.   Вставить как обычный текст

  Разрешено использовать не более 75 эмодзи.

×   Ваша ссылка была автоматически встроена.   Отображать как обычную ссылку

×   Ваш предыдущий контент был восстановлен.   Очистить редактор

×   Вы не можете вставлять изображения напрямую. Загружайте или вставляйте изображения по ссылке.

Загрузка...
 Поделиться

×
×
  • Создать...

Важная информация

Используя наш сайт вы соглашаетесь с нашей Политикой конфиденциальности