V
V
Vadim Timoshenko2020-02-07 18:15:52
1C-Bitrix
Vadim Timoshenko, 2020-02-07 18:15:52

How to merge the header of all 1C-Bitrix templates?

I'm sitting figuring out someone else's 1C-Bitrix site/code.

I want to change the layout a bit. Thanks to the documentation, it finally dawned on me that in Bitrix there is not one template as usual for the entire site, but a bunch of different templates for different pages. At least that's what the developer did before me.

  • /local/templates/index/ - for the main page
  • /local/templates/main/ - for other pages
  • /local/templates/fullscreen_services/ - for service pages
  • /local/templates/detail/ - for contacts and so on.


But the fact is that most of these pages, especially footer.php and header.php are almost the same. The difference happens in 1-2 .js, .css files. And in order to make changes to or I need to change the file in all templates. Some hemorrhoid.

Is this the suffering of Bitrix developers or is there a correct solution? There is some common header.php/footer.php file where I can write everything 1 time. And how can I, according to the condition of the page id or its type, or some other parameter, load the scripts I need pointwise?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-02-07
@PbI6A_KuT

Thanks to the documentation, it finally dawned on me that in Bitrix there is not one template as usual for the entire site, but a bunch of different templates for different pages.

This is not entirely true. Usually there is only one template. But you can make your own for each page.
But the fact is that most of these pages, especially footer.php and header.php are almost the same. The difference happens in 1-2 .js, .css files.

If the differences are only in the included files, then it is completely wrong to make templates different for pages. The template should be one, and js and css should classically be connected by the components that need them, or at least on the pages themselves.
Is this the suffering of Bitrix developers or is there a correct solution?

There is. Described above.
There is some common header.php/footer.php file where I can write everything 1 time.

Nothing stops you from doing them. For example, many place such files in /local/layout and include them inside different templates in their header.php/footer.php
I still sometimes put them in /local/templates/.default
And how can I, according to the condition of the page id or its type, or some other parameter, load the scripts I need pointwise?

It's not needed. Include in the pages themselves with Asset::getInstance()->addJs("/my_scripts.js");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question