E
E
Express7772015-02-22 09:05:28
1C-Bitrix
Express777, 2015-02-22 09:05:28

Display different headers on the page of the main section, subsection, detailed news in Bitrix?

Hello.
There is a task to display a different piece of HTML code on the page of the main section, subsection, detailed news.
Initial data:
Bitrix 15 versions, standard.
Main page, mysite.com. Mysite.com/news/ section, where to deploy the complex news component. The complex component takes data from one information block news (the symbolic code is the same as the name of the physical section).
The CNC of the complex component news is configured as follows:


CNC directory (relative to site root): /news/
Section page: #SECTION_CODE_PATH#/
Detail page: #SECTION_CODE_PATH#/#ELEMENT_ID#/

#SECTION_CODE_PATH#/ because sections have subsections.
CNC works fine. mysite.com/news/ displays all elements from the infoblock news. mysite.com/news/section1/ all elements from the section1 infoblock. mysite.com/news/section1/11/ detailed news.
I need to insert 4 relatively different sidebars into the header. The content in them changes depending on the page.
On the main page of mysite.com sidebar1.
mysite.com/news/ sidebar2
mysite.com/news/section title/ sidebar3
In the detailed news sidebar4.
It would be possible to put a condition on the url. But the title of the section and the title of the detailed news are generated dynamically. The section title can be deeply nested. That is mysite.com/news/section1/subsection1/subsubsection1/
It would be possible to insert a sidebar into the template of the section and detailed news components. But in this case flexibility is lost. Today is news, tomorrow articles with a different template. And shove a sidebar2 into each of them. That will be supported by other programmers. They may not understand this code :)
Is there some kind of global constant in Bitrix that determines the page type.? So that you can put a condition in the header.
If the page type is "main section", do that. If the page type is "subsection" then do that. If "detailed news", etc.
Maybe there are some other solutions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Emelyanov, 2015-02-22
@Express777

To begin with, in the header, where the sidebar html should be, place
it - buffered output will be here .
Then, inside the complex news component, you create component_epilog.php files in the news.detail and news.list templates. For each of these templates in component_epilog.php you create a global variable, for example
or
Next, in the footer of the site template, check the value of $SIDEBAR_FOR and, depending on it, make the buffered output in header.php using the AddViewContent("sidebar", $html_sidebar) function.

A
Alexander, 2015-02-22
Madzhugin @Suntechnic

Do not use complex components.
Do not use CNC settings in components.
It's all made to sell, not to use ;)
My opinion: a complex component is almost always bad, and in rare cases - very bad.
There are 100,500 options for implementation.
1 Completely different templates with different headers and switching, let's say by a constant, which should be set directly on the page before connecting the header and starting the kernel. Here it is necessary to abandon the complex component so that the scripts mysite.com/news/ and mysite.com/news/section title/, as well as the detailed news page, are really different. What is not very good is that mysite.com/news/ is essentially a special case of mysite.com/news/section title/.
2 Using deferred functions, postpone the creation of the sidebar until the execution of the complex component. Depending on its result, form a sidebar. How to get the result is the tenth thing - you can build the generation into the epilogues of the complex components, you can set some variable and then react to its value.
3 js
3.1 Same as two, but generate a dynamic inline script that will create a sidebar. More precisely, there should be one creation script - generate data for it depending on the result of the component, so that this script creates a sidebar from this data.
3.2 Postpone the creation of the sidebar even further. Let your components upload some value in js to the page, and after loading get the sidebar with ajax.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question