How to enable the CNC in the bitrix news.list component

The site has an inform folder with 2 files in it index.php and detail.php In the file index.php the news.list component is called, in the file detail.php the news.detail component is called. In the file index.php if set to DETAIL_URL=/inform/detail. php?ELEMENT_CODE=#ELEMENT_CODE# the detailed news is output, if nothing is set or set to DETAIL_URL=/inform/#ELEMENT_CODE#/ the detailed news is not output instead of an empty white page there are no errors on it. I tried using it instead of news. list the news component does the same thing.

How do I change the DETAIL_URL so that the detail page is displayed and the URL looks like /inform/frukty/ ????????

Here are the component codes and the file code urlrewrite.php

File code index.php in the inform{[5] folder]}

<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
?><h1>Информация</h1>
<div class="tile">
	<?$APPLICATION->IncludeComponent("bitrix:news.list", "inform_l", array(
	"IBLOCK_TYPE" => "cont",
	"IBLOCK_ID" => "3",
	"NEWS_COUNT" => "100",
	"SORT_BY1" => "ACTIVE_FROM",
	"SORT_ORDER1" => "ASC",
	"SORT_BY2" => "ACTIVE_FROM",
	"SORT_ORDER2" => "ASC",
	"FILTER_NAME" => "",
	"FIELD_CODE" => array(
		0 => "NAME",
		1 => "",
	),
	"PROPERTY_CODE" => array(
		0 => "",
		1 => "",
	),
	"CHECK_DATES" => "Y",
	"DETAIL_URL" => "/inform/detail.php?ELEMENT_CODE=#ELEMENT_CODE#",
	"AJAX_MODE" => "N",
	"AJAX_OPTION_JUMP" => "N",
	"AJAX_OPTION_STYLE" => "Y",
	"AJAX_OPTION_HISTORY" => "N",
	"CACHE_TYPE" => "A",
	"CACHE_TIME" => "36000000",
	"CACHE_FILTER" => "N",
	"CACHE_GROUPS" => "N",
	"PREVIEW_TRUNCATE_LEN" => "",
	"ACTIVE_DATE_FORMAT" => "d.m.y G:i",
	"SET_TITLE" => "Y",
	"SET_STATUS_404" => "Y",
	"INCLUDE_IBLOCK_INTO_CHAIN" => "N",
	"ADD_SECTIONS_CHAIN" => "N",
	"HIDE_LINK_WHEN_NO_DETAIL" => "N",
	"PARENT_SECTION" => "4",
	"PARENT_SECTION_CODE" => "",
	"DISPLAY_TOP_PAGER" => "N",
	"DISPLAY_BOTTOM_PAGER" => "Y",
	"PAGER_TITLE" => "Информация",
	"PAGER_SHOW_ALWAYS" => "N",
	"PAGER_TEMPLATE" => "pagenav",
	"PAGER_DESC_NUMBERING" => "N",
	"PAGER_DESC_NUMBERING_CACHE_TIME" => "36000",
	"PAGER_SHOW_ALL" => "N",
	"DISPLAY_DATE" => "N",
	"DISPLAY_NAME" => "Y",
	"DISPLAY_PICTURE" => "N",
	"DISPLAY_PREVIEW_TEXT" => "N",
	"AJAX_OPTION_ADDITIONAL" => ""
	),
	false
);?>
</div>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>

File code detail.php in the inform{[5] folder]}

<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("Заголовок");
?><?$APPLICATION->IncludeComponent("bitrix:news.detail", "inform_detail", array(
	"IBLOCK_TYPE" => "cont",
	"IBLOCK_ID" => "3",
	"ELEMENT_ID" => $_REQUEST["ID"],
	"ELEMENT_CODE" => $_REQUEST["ELEMENT_CODE"],
	"CHECK_DATES" => "Y",
	"FIELD_CODE" => array(
		0 => "",
		1 => "",
	),
	"PROPERTY_CODE" => array(
		0 => "",
		1 => "",
	),
	"IBLOCK_URL" => "",
	"AJAX_MODE" => "N",
	"AJAX_OPTION_JUMP" => "N",
	"AJAX_OPTION_STYLE" => "Y",
	"AJAX_OPTION_HISTORY" => "N",
	"CACHE_TYPE" => "A",
	"CACHE_TIME" => "36000000",
	"CACHE_GROUPS" => "Y",
	"META_KEYWORDS" => "-",
	"META_DESCRIPTION" => "-",
	"BROWSER_TITLE" => "SEO_T",
	"SET_TITLE" => "Y",
	"SET_STATUS_404" => "Y",
	"INCLUDE_IBLOCK_INTO_CHAIN" => "Y",
	"ADD_SECTIONS_CHAIN" => "N",
	"ACTIVE_DATE_FORMAT" => "d.m.Y",
	"USE_PERMISSIONS" => "N",
	"DISPLAY_TOP_PAGER" => "N",
	"DISPLAY_BOTTOM_PAGER" => "Y",
	"PAGER_TITLE" => "Страница",
	"PAGER_TEMPLATE" => "inform_detail",
	"PAGER_SHOW_ALL" => "Y",
	"DISPLAY_DATE" => "Y",
	"DISPLAY_NAME" => "Y",
	"DISPLAY_PICTURE" => "Y",
	"DISPLAY_PREVIEW_TEXT" => "Y",
	"USE_SHARE" => "N",
	"AJAX_OPTION_ADDITIONAL" => ""
	),
	false
);?> <?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>

File code urlrewrite.php

<?
$arUrlRewrite = array(
	array(
		"CONDITION"	=>	"#^/inform/([^/]+)/($|\\?.*)#",
		"RULE"	=>	"ELEMENT_CODE=$1",
		"ID"	=>	"",
		"PATH"	=>	"/inform/detail.php",
	),
	array(
		"CONDITION"	=>	"#^/inform/#",
		"RULE"	=>	"bitrix:news.list",
		"ID"	=>	"",
		"PATH"	=>	"/inform/index.php",
	)
);

?>

Template code info_list

<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
<ul>
<?/*if($arParams["DISPLAY_TOP_PAGER"]):?>
	<?=$arResult["NAV_STRING"]?><br />
<?endif;*/?>
<?foreach($arResult["ITEMS"] as $arItem):?>
	<?
	$this->AddEditAction($arItem['ID'], $arItem['EDIT_LINK'], CIBlock::GetArrayByID($arItem["IBLOCK_ID"], "ELEMENT_EDIT"));
	$this->AddDeleteAction($arItem['ID'], $arItem['DELETE_LINK'], CIBlock::GetArrayByID($arItem["IBLOCK_ID"], "ELEMENT_DELETE"), array("CONFIRM" => GetMessage('CT_BNL_ELEMENT_DELETE_CONFIRM')));
	?>

			<li><a href="<?echo $arItem["DETAIL_PAGE_URL"]?>"><?echo $arItem["NAME"]?></a></li>

<?endforeach;?>
<?/*if($arParams["DISPLAY_BOTTOM_PAGER"]):?>
	<?=$arResult["NAV_STRING"]?>
<?endif;*/?>
</ul>
Author: Demon, 2020-01-16

1 answers

In your implementation, with what has already been done, you can do this:

  • in the file urlrewrite.php probably not what it is, here is an example

Instead,:

array(
    "CONDITION" =>  "#^/inform/([^/]+)/($|\\?.*)#",
    "RULE"  =>  "ELEMENT_CODE=$1",
    "ID"    =>  "",
    "PATH"  =>  "/inform/detail.php",
),

Try this way (i.e. the second part after /inform/ is selected from the url, which can be characters and numbers, and what is found will be passed to the file /inform/detail.php in $_REQUEST ['ELEMENT_CODE’], and in this file you will already use where you want ):

array ( 
    'CONDITION' => '#^/inform/([a-zA-Z0-9_-]+)/?(.*)#',
    'RULE' => 'ELEMENT_CODE=$1',
    'ID' => '',
    'PATH' => '/inform/detail.php',
),
  • In the file index.php specify DETAIL_URL = "/inform/#ELEMENT_CODE# " (then the urls in the template will be composed of this type, /inform/ )
  • a in the file detail.php remove the line "ELEMENT_ID" = > $_REQUEST ["ID"] (after all, you are not going to pass the product id and in the file urlrewrite.php this option was not described, and in this file you will have the code of the element from the url in the variable $_REQUEST ['ELEMENT_CODE’] which you already throw into the component)

But test it maybe a little different regularity is needed (you can find in the documentation).

If the screen is white, then you need to enable the output of php errors in bitrix.

(Well, it would probably be easier to use the integrated component of news - there are a lot of articles and documentation on it)

 0
Author: ssv32, 2020-01-17 07:56:26