Answer the question
In order to leave comments, you need to log in
How to form your link in the CNC in a complex component?
Good evening. Tell me please.
I use bitrix:news complex component.
The CNC was previously formed via /news/1234.html - where 1234 is the id of the news
. Moreover, the news with id 1234 is in the section section.
That is, the link template had the form
"section" => "#SECTION_CODE_PATH#/",
"detail" => "#ELEMENT_ID#.html",
Now we need to make sure that the new added news has a normal NC of the form
"section" => "#SECTION_CODE_PATH#/",
"detail" => "#SECTION_CODE_PATH#/"#ELEMENT_CODE#/",
But at the same time, the old news should remain with the old url - /news/1234.html
I don't know how to make new was a new url, and the old ones have an old one.
I wanted to use the SetUrlTemplates function
I wrote it in the result_modifier in news.list - but it didn't work - it gives a 404 error page.
Here is the code on the example of one ID
$rsElements = CIBlockElement::GetList(array(), array("ID" => 384857, "IBLOCK_ID" => 19), false, false, array("ID", "NAME", "DETAIL_PAGE_URL"));
$rsElements->SetUrlTemplates("/news/#SECTION_CODE_PATH#/#ELEMENT_CODE#.html");
$arElement = $rsElements->GetNext();
foreach($arResult["ITEMS"] as $key => $val){
if($val["ID"] == $arElement["ID"]){
$arResult["ITEMS"][$key]["DETAIL_PAGE_URL"] = $arElement["DETAIL_PAGE_URL"];
}
}
Answer the question
In order to leave comments, you need to log in
No need to create duplicate pages. Do a redirect. If there are not many elements, then make a list and write redirects in htaccess. If there is a lot, then you can check the url on 404 for belonging to the old CNC template, if you find one, then do a redirect through LocalRedirect
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question