G
G
GhostWithin2019-07-10 17:04:23
1C-Bitrix
GhostWithin, 2019-07-10 17:04:23

How to insert a repeating piece of html code into the Bitrix information block?

There are a number of information blocks that are the content for the page.
There are several pieces of html code that need to be inserted into these blocks.
The most primitive solution is to push the code into each block by hand, but in order to make adjustments later, you will have to edit a dozen pages.
Inserting them through a template is not an option, because. in total there are two dozen infoblocks and about 10 "pieces of code to insert". And they will be inserted in different combinations into different infoblocks.
I would like to do it by analogy with other CMS, for example, MODx.
There are chunks - pieces of html code. A "reference" to the chunk is inserted in the right place and, if necessary, the chunk itself is edited and the changes are displayed everywhere. I saw that in Bitrix you can achieve the same through include, but this does not work in the info block.
The experience with Bitrix is ​​slightly more than 0.
The picture below shows where I am trying to set the repeating code
5d25f0023ff6f570551417.png
5d25f0485023f688003292.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Skibin, 2019-07-10
@GhostWithin

In the text field of the info block out of the box, you can’t place it like that. In your case - I would advise you to place in the template through

$APPLICATION->IncludeFile(
      $APPLICATION->GetTemplatePath("include/sometext.php"),
      [],
      ["MODE" => "html"]
);

place the file itself in the include/sometext.php template and edit it through the same public part as "edit the include area"

R
Roman Gritsuk, 2019-07-10
@winer

If your HTML blocks that need to be added to DETAIL_TEXT have the same content, then this can be done by inserting labels within DETAIL_TEXT.
For example, there is a description, and in the right place you add a construction like #CUSTOM_BLOCK#.
After that, in the component template, use a regular expression to look for such blocks and replace them with what you need.
If there are many such blocks, then it can be done in several ways:
1) Through files. Create a folder /html_blocks/ in it throw your html blocks in separate files. Make labels in the form #CUSTOM_BLOCK_1#, #CUSTOM_BLOCK_2#. And accordingly, for such labels, it will be necessary to insert content from the files /html_blocks/1.php, /html_blocks/2.php
2) Through a separate IS. In it, create the HTML blocks you need. Labels are organized according to the same #CUSTOM_BLOCK_N# principle. But with the insertion there will be more problems. You can do it as it is written here https://dev.1c-bitrix.ru/learning/course/index.php... . Only in the example, bitrix:voting.current is connected, and in your case it will be bitrix:news.detail

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question