G
G
gnvs2021-07-02 17:55:50
1C-Bitrix
gnvs, 2021-07-02 17:55:50

Competently write the conditions for the section?

Good time,
I collect a non-standard template.
I created a section, let's say News, put the complex news component there.
The question is that in the section itself I have one layout for crumbs, headlines, news.list. Everything in detail.

It turns out that I need to set a condition specifically for news and for detailed ones.

I tried options like

There is something like this:

<?// Это нужно включить ТОЛЬКО для индексной страницы news ?>
<?if (($APPLICATION->GetCurDir()=='/news/')):?>

<div class="container">

    <div class="title-container">
      <div class="title-container__text">
        <h1 class="title"><?$APPLICATION->ShowTitle(false);?></h1>
      </div>
      <div class="title-container__link">
        <a href="#">Предложить свою новость</a>
      </div>
    </div>

<?$APPLICATION->IncludeComponent(
    "bitrix:breadcrumb", 
    "breadcrumbs", 
      array(
        "COMPONENT_TEMPLATE" => "breadcrumbs",
        "START_FROM" => "0",
        "PATH" => "",
        "SITE_ID" => "s1"
  ),
  false
);?>

</div>

<div class="container">
<section class="news">
    <div class="news__panel">
        <div class="form">
          <form>
                   <input type="search" placeholder="Поиск по сайту...">
          </form>
        </div>

    </div>

<?else:?>

<?// Это подключается ТОЛЬКО для элементов?>
<div class="title-container-bg" style="background-image: url('/local/templates/default_kvz/img/content/comments-bg.jpg')">
    	<div class="container">
      		<h1><?$APPLICATION->ShowTitle(false);?></h1>
    	</div>
  	</div>

  <div class="container pt-2">
    <?$APPLICATION->IncludeComponent(
      "bitrix:breadcrumb", 
      "breadcrumbs", 
      array(
        "COMPONENT_TEMPLATE" => "breadcrumbs",
        "START_FROM" => "0",
        "PATH" => "",
        "SITE_ID" => "s1"
    ),
    false
    );?>
  </div>
  
<?endif;?>


The variant specified above does not work, specified for an example.
I tried several options that were in the documentation, but they do not suit me.
I ask for advice on this matter.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2021-07-03
@gnvs

Place the block that is needed only on the element list pages in the section.php file of the complex component template, and the block that is needed on the detail page in the element.php file of this template.
Hardcore paths in the code is not worth it.

E
Edward, 2021-07-03
@Drayde

Watch the course on design customization in Bitrix.
https://academy.1c-bitrix.ru/training/course/5862/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question