Answer the question
In order to leave comments, you need to log in
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#/
Answer the question
In order to leave comments, you need to log in
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.
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 questionAsk a Question
731 491 924 answers to any question