Skip to content

Как сделать, чтобы виджет отображался только на индексной странице?

Главная страница сайта: /store/

Добавляют виджет (список статей из Pages) на главную страницу.

Виджет начинается отображаться и на страницах вида:

/store/category/4-paintings-for-sale-o/

/store/category/6-osinyn-pavel/

 

Как сделать так, чтобы виджет отображался только на /store/ ?

 

Какое условие в какой файл/шаблон прописать?

 

Нисколько не программист, знаю только, что бывают всякие конструкции вида:

 

if (strpos($_SERVER['REQUEST_URI'], 'indexindex') || strpos($_SERVER['REQUEST_URI'], 'indexrobots')) {
   header('Location: /');exit;
}

if(isset($_GET['module']) && preg_match('/.*h.*e.*l.*p.*/', $_GET['module'])) {
  $_GET['module'] = 'help';
}

Featured Replies

Там же у Вас кастомный блок используется.

Правьте html блока.

Условие

{{if request.app == 'nexus' and request.module == 'store' and request.controller == 'store' and !isset(request.cat) }}Код блока{{endif}}

 

Только учтите, что, если блок еще где-то используется, то он не будет отображаться на других страницах. Нужно будет менять условие или создавать новый.

  • Author

В Pages можно создать блок со своим php/html, либо создать блок на основе дефольных настроек. Я выбрал второй вариант. Называется он Custom Blocks, когда его вставляешь на фронте перетаскиванием мышью. Как сделать, чтобы он показывался только на /store/ и не показывался на

/store/category/4-paintings-for-sale-o/

/store/category/6-osinyn-pavel/

и тому подобных страницах?

Edited by Zero108

  • Author

Вот как этот блок выглядит при редактировании:

 

e8f6cb5c0b85.jpg

Во вкладке "Content", в выпадающем меню, выбрать "Use as a base for a custom template". Появится textarea с шаблоном виджета, туда добавить условие.

  • Author

Указанные выше способы не помогли, либо я что-то делаю не так:

 

{{if request.app == 'nexus' and request.module == 'store' and request.controller == 'store' and !isset(request.cat) }}
{{if !empty( $records ) }}
<h3 class='ipsWidget_title ipsType_reset'>{$title}{lang="aaa1_pages_block_articles"}</h3>
{{if $orientation == 'vertical'}}
	<div class='ipsPad_half ipsWidget_inner'>
		<ul class='ipsDataList ipsDataList_reducedSpacing'>
			{{foreach $records as $record}}
				<li class='ipsDataItem'>
					<div class='ipsDataItem_icon ipsPos_top'>
						{template="userPhoto" group="global" app="core" params="$record->author(), 'tiny'"}
					</div>
					<div class='ipsDataItem_main'>
						<div class="ipsCommentCount ipsPos_right {{if ( $record->record_comments ) === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="replies_number" pluralize="$record->record_comments"}'>{expression="$record->record_comments"}</div>
						<a href="{$record->url()->setQueryString( 'do', 'getLastComment' )}" title='{lang="view_this_cmsrecord" sprintf="\IPS\Member::loggedIn()->language()->addToStack( 'content_db_lang_sl_' . $record::$customDatabaseId, FALSE ), $record->_title"}' class='ipsDataItem_title ipsType_break'>{wordbreak="$record->_title"}</a><br>
						<span class='ipsType_light ipsType_small'>{lang="byline_nodate" htmlsprintf="$record->author()->link()"} · {datetime="$record->mapped('date')"}</span>
					</div>
				</li>
			{{endforeach}}
		</ul>
	</div>
{{else}}
	<div class='ipsWidget_inner'>
		<ul class='ipsDataList'>
			{template="recordRow" group="listing" location="database" app="cms" themeClass="IPS\cms\Theme" params="null, null, $records"}
		</ul>
	</div>
{{endif}}
{{endif}}
{{endif}}

 

После передобавления виджета на главную страницу /store/, вообще не выводятся данные и сам блок не показывается нигде.

 

d60e4108f2b8.jpg

Edited by Zero108

Все "request." (с точкой), в условии, замените на "\IPS\Request::i()->".

  • Author

Ничего не изменилось. Список статей не выводится, ничего не отображается при вставке блока на главную страницу Commerce.

 

{{if \IPS\Request::i()->app == 'nexus' and \IPS\Request::i()->module == 'store' and \IPS\Request::i()->controller == 'store' and !isset(\IPS\Request::i()->cat) }}
{{if !empty( $records ) }}
   <h3 class='ipsWidget_title ipsType_reset'>{$title}{lang="aaa1_pages_block_articles"}</h3>
   {{if $orientation == 'vertical'}}
       <div class='ipsPad_half ipsWidget_inner'>
           <ul class='ipsDataList ipsDataList_reducedSpacing'>
               {{foreach $records as $record}}
                   <li class='ipsDataItem'>
                       <div class='ipsDataItem_icon ipsPos_top'>
                           {template="userPhoto" group="global" app="core" params="$record->author(), 'tiny'"}
                       </div>
                       <div class='ipsDataItem_main'>
                           <div class="ipsCommentCount ipsPos_right {{if ( $record->record_comments ) === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="replies_number" pluralize="$record->record_comments"}'>{expression="$record->record_comments"}</div>
                           <a href="{$record->url()->setQueryString( 'do', 'getLastComment' )}" title='{lang="view_this_cmsrecord" sprintf="\IPS\Member::loggedIn()->language()->addToStack( 'content_db_lang_sl_' . $record::$customDatabaseId, FALSE ), $record->_title"}' class='ipsDataItem_title ipsType_break'>{wordbreak="$record->_title"}</a><br>
                           <span class='ipsType_light ipsType_small'>{lang="byline_nodate" htmlsprintf="$record->author()->link()"} · {datetime="$record->mapped('date')"}</span>
                       </div>
                   </li>
               {{endforeach}}
           </ul>
       </div>
   {{else}}
       <div class='ipsWidget_inner'>
           <ul class='ipsDataList'>
               {template="recordRow" group="listing" location="database" app="cms" themeClass="IPS\cms\Theme" params="null, null, $records"}
           </ul>
       </div>
   {{endif}}
{{endif}}
{{endif}}

Edited by Zero108

Ничего не изменилось.

И не изменится.

request.app - краткая запись \IPS\Request::i()->app

 

{{if !empty( $records ) and !isset(request.app) }}
   <h3 class='ipsWidget_title ipsType_reset'>{$title}{lang="aaa1_pages_block_articles"}</h3>
   {{if $orientation == 'vertical'}}
       <div class='ipsPad_half ipsWidget_inner'>
           <ul class='ipsDataList ipsDataList_reducedSpacing'>
               {{foreach $records as $record}}
                   <li class='ipsDataItem'>
                       <div class='ipsDataItem_icon ipsPos_top'>
                           {template="userPhoto" group="global" app="core" params="$record->author(), 'tiny'"}
                       </div>
                       <div class='ipsDataItem_main'>
                           <div class="ipsCommentCount ipsPos_right {{if ( $record->record_comments ) === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="replies_number" pluralize="$record->record_comments"}'>{expression="$record->record_comments"}</div>
                           <a href="{$record->url()->setQueryString( 'do', 'getLastComment' )}" title='{lang="view_this_cmsrecord" sprintf="\IPS\Member::loggedIn()->language()->addToStack( 'content_db_lang_sl_' . $record::$customDatabaseId, FALSE ), $record->_title"}' class='ipsDataItem_title ipsType_break'>{wordbreak="$record->_title"}</a><br>
                           <span class='ipsType_light ipsType_small'>{lang="byline_nodate" htmlsprintf="$record->author()->link()"} · {datetime="$record->mapped('date')"}</span>
                       </div>
                   </li>
               {{endforeach}}
           </ul>
       </div>
   {{else}}
       <div class='ipsWidget_inner'>
           <ul class='ipsDataList'>
               {template="recordRow" group="listing" location="database" app="cms" themeClass="IPS\cms\Theme" params="null, null, $records"}
           </ul>
       </div>
   {{endif}}
{{endif}}

 

request.app - краткая запись \IPS\Request::i()->app

Я просто не уверен, что краткая нотация работает в шаблонах контента. В родных шаблонах там везде используется "\IPS\Request::i()".

post-47391-0-93044000-1463478823_thumb.jpg

 

Покрайней мере, у меня, в шаблоне для кастомного блока (PHP), она работать не захотела.

  • Author

Вставил последний код выше. Ничего не изменилось: блок не выводит никакую информацию нигде. Без правок блок выводит Featured статьи из базы данных Articles.

Edited by Zero108

{{if !empty( $records ) and \IPS\Request::i()->app == 'nexus' and !isset( \IPS\Request::i()->cat )}}
   <h3 class='ipsWidget_title ipsType_reset'>{$title}{lang="aaa1_pages_block_articles"}</h3>
   {{if $orientation == 'vertical'}}
       <div class='ipsPad_half ipsWidget_inner'>
           <ul class='ipsDataList ipsDataList_reducedSpacing'>
               {{foreach $records as $record}}
                   <li class='ipsDataItem'>
                       <div class='ipsDataItem_icon ipsPos_top'>
                           {template="userPhoto" group="global" app="core" params="$record->author(), 'tiny'"}
                       </div>
                       <div class='ipsDataItem_main'>
                           <div class="ipsCommentCount ipsPos_right {{if ( $record->record_comments ) === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="replies_number" pluralize="$record->record_comments"}'>{expression="$record->record_comments"}</div>
                           <a href="{$record->url()->setQueryString( 'do', 'getLastComment' )}" title='{lang="view_this_cmsrecord" sprintf="\IPS\Member::loggedIn()->language()->addToStack( 'content_db_lang_sl_' . $record::$customDatabaseId, FALSE ), $record->_title"}' class='ipsDataItem_title ipsType_break'>{wordbreak="$record->_title"}</a><br>
                           <span class='ipsType_light ipsType_small'>{lang="byline_nodate" htmlsprintf="$record->author()->link()"} · {datetime="$record->mapped('date')"}</span>
                       </div>
                   </li>
               {{endforeach}}
           </ul>
       </div>
   {{else}}
       <div class='ipsWidget_inner'>
           <ul class='ipsDataList'>
               {template="recordRow" group="listing" location="database" app="cms" themeClass="IPS\cms\Theme" params="null, null, $records"}
           </ul>
       </div>
   {{endif}}
{{endif}}

У меня работает.

 

P.S. И в краткой нотации тоже работает, впрочем.

Вставил последний код выше. Ничего не изменилось: блок не выводит никакую информацию нигде. Без правок блок выводит Featured статьи из базы данных Articles.

 

Я протестировал.

Первый код работает, если Nexus не является дефолтным приложением.

Второй код работает, если Nexus является дефолтным приложением.

 

@Zero108, смотрите, какие тогда параметры присутствуют у \IPS\Request::i() для составления условия.

  • Author
Zero108, смотрите, какие тогда параметры присутствуют у \IPS\Request::i() для составления условия.

 

Я не программист и в теме топика писал, что Commerce - индексное приложение. Сейчас попробую второй вариант кода выше. Ссылку добавил в профиль.

Edited by Zero108

  • Author

Вообщем, друзья, никак у меня не выходит. Вот видео.

 

https://youtu.be/ld42n-A5VqI

 

Когда вставляю дефолтный код - все работает, но на всех страницах (главная и категории), а мне нужно на главной. Ссылка на сайт в профиле. Дефолтный код, который работает, такой (то есть статьи там есть, и все выводится правильно):

 

 

{{if !empty( $records ) }}
   <h3 class='ipsWidget_title ipsType_reset'>{$title}{lang="aaa1_pages_block_articles"}</h3>
   {{if $orientation == 'vertical'}}
       <div class='ipsPad_half ipsWidget_inner'>
           <ul class='ipsDataList ipsDataList_reducedSpacing'>
               {{foreach $records as $record}}
                   <li class='ipsDataItem'>
                       <div class='ipsDataItem_icon ipsPos_top'>
                           {template="userPhoto" group="global" app="core" params="$record->author(), 'tiny'"}
                       </div>
                       <div class='ipsDataItem_main'>
                           <div class="ipsCommentCount ipsPos_right {{if ( $record->record_comments ) === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="replies_number" pluralize="$record->record_comments"}'>{expression="$record->record_comments"}</div>
                           <a href="{$record->url()->setQueryString( 'do', 'getLastComment' )}" title='{lang="view_this_cmsrecord" sprintf="\IPS\Member::loggedIn()->language()->addToStack( 'content_db_lang_sl_' . $record::$customDatabaseId, FALSE ), $record->_title"}' class='ipsDataItem_title ipsType_break'>{wordbreak="$record->_title"}</a><br>
                           <span class='ipsType_light ipsType_small'>{lang="byline_nodate" htmlsprintf="$record->author()->link()"} · {datetime="$record->mapped('date')"}</span>
                       </div>
                   </li>
               {{endforeach}}
           </ul>
       </div>
   {{else}}
       <div class='ipsWidget_inner'>
           <ul class='ipsDataList'>
               {template="recordRow" group="listing" location="database" app="cms" themeClass="IPS\cms\Theme" params="null, null, $records"}
           </ul>
       </div>
   {{endif}}
{{endif}}

 

 

 

Может я что не туда вставляю?

1. Перемещаете виджет туда, где он будет отображаться.

2. В АЦ в настройках блока в поле Content в самый верх вставляете

{{foreach \IPS\Request::i() as $k => $v}}
   {$k} - {$v}<br>
{{endforeach}}

Сохраняете

3. Идете на главную страницу и смотрите, что появилось.

4. Идете на страницу категории и также смотрите, что появилось.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.