V
V
viktorulyushev2017-03-09 12:32:22
css
viktorulyushev, 2017-03-09 12:32:22

Bitrix.Component call is perceived as text?

Here is the page template

<?php
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();

/**
 * @global CMain $APPLICATION
 */

global $APPLICATION;

//delayed function must return a string
if(empty($arResult))
  return "";

$strReturn = '';

//we can't use $APPLICATION->SetAdditionalCSS() here because we are inside the buffered function GetNavChain()
$css = $APPLICATION->GetCSSArray();
if(!is_array($css) || !in_array("/bitrix/css/main/font-awesome.css", $css))
{
  $strReturn .= '<link href="'.CUtil::GetAdditionalFileURL("/bitrix/css/main/font-awesome.css").'" type="text/css" rel="stylesheet" />'."\n";
}

$strReturn .= '<div class="bx-breadcrumb">';

$itemSize = count($arResult);
for($index = 0; $index < $itemSize; $index++)
{
  $title = htmlspecialcharsex($arResult[$index]["TITLE"]);

  $nextRef = ($index < $itemSize-2 && $arResult[$index+1]["LINK"] <> ""? ' itemref="bx_breadcrumb_'.($index+1).'"' : '');
  $child = ($index > 0? ' itemprop="child"' : '');
  $arrow = ($index > 0? '<i class="fa fa-angle-right"></i>' : '');

  if($arResult[$index]["LINK"] <> "" && $index != $itemSize-1)
  {

  }
  else if(empty($arResult[2]))
  {
    $strReturn .= '
      <ul class="crumbs">
<li><a href="/index.php">Главная</a></li style="padding: 0 10px 0 3px;"><li style="padding: 0 10px 0 3px;"><a href="/catalog/">Каталог</a></li style="padding: 0 10px 0 3px;"><li style="padding: 0 10px 0 3px;"><a href="/catalog/new/">Вилочные погрузчики</a></li>
<li style="padding: 0 10px 0 3px;"><a href="'.$arResult[1]["LINK"].'">'.$arResult[1]["TITLE"].'</a></li>
      </ul>';
  } else
  {
    $strReturn .= '
      <ul class="crumbs">
<li><a href="/index.php">Главная</a></li style="padding: 0 10px 0 3px;"><li style="padding: 0 10px 0 3px;"><a href="/catalog/">Каталог</a></li style="padding: 0 10px 0 3px;"><li style="padding: 0 10px 0 3px;"><a href="/catalog/new/">Вилочные погрузчики</a>
                <ul class="sub-menu">
<?$APPLICATION->IncludeComponent(
  "bitrix:catalog.section.list", 
  "4k2_section_breadcrumb", 
  array(
    "ADD_SECTIONS_CHAIN" => "Y",
    "CACHE_GROUPS" => "Y",
    "CACHE_TIME" => "36000000",
    "CACHE_TYPE" => "A",
    "COUNT_ELEMENTS" => "N",
    "IBLOCK_ID" => "17",
    "IBLOCK_TYPE" => "4k2_catalog",
    "SECTION_CODE" => "",
    "SECTION_FIELDS" => array(
      0 => "NAME",
      1 => "",
    ),
    "SECTION_ID" => $_REQUEST["SECTION_ID"],
    "SECTION_URL" => "#SITE_DIR#/catalog/new/#SECTION_ID#/",
    "SECTION_USER_FIELDS" => array(
      0 => "",
      1 => "",
    ),
    "SHOW_PARENT_NAME" => "Y",
    "TOP_DEPTH" => "1",
    "VIEW_MODE" => "LINE",
    "COMPONENT_TEMPLATE" => ".default"
  ),
  false
);?>
                </ul>
</li>
<li style="padding: 0 10px 0 3px;"><a href="'.$arResult[1]["LINK"].'">'.$arResult[1]["TITLE"].'</a></li>
<li style="padding: 0 10px 0 3px;"><a href="'.$arResult[2]["LINK"].'">'.$arResult[2]["TITLE"].'</a></li>
      </ul>';
  }
}

$strReturn .= '<div style="clear:both"></div></div>';

return $strReturn;

At the bottom I have a component call for bitrix:catalog.section.list where I display a list of sections and want to display them in a drop-down list, but it is perceived as text only, how to make php work, play with . and ' tried, does not help.

Maybe js can be transferred somehow?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita, 2017-03-09
@viktorulyushev

in the example, even the component is displayed as text and it is immediately visible.
Take the component out of echo.
In general, calling a component from a component is not the best practice, you will have everything in the cache all the time.

V
viktorulyushev, 2017-03-09
@viktorulyushev

<?php
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();

/**
 * @global CMain $APPLICATION
 */

global $APPLICATION;

//delayed function must return a string
if(empty($arResult))
  return "";

$strReturn = '';

//we can't use $APPLICATION->SetAdditionalCSS() here because we are inside the buffered function GetNavChain()
$css = $APPLICATION->GetCSSArray();
if(!is_array($css) || !in_array("/bitrix/css/main/font-awesome.css", $css))
{
  $strReturn .= '<link href="'.CUtil::GetAdditionalFileURL("/bitrix/css/main/font-awesome.css").'" type="text/css" rel="stylesheet" />'."\n";
}

$strReturn .= '<div class="bx-breadcrumb">';

$itemSize = count($arResult);
for($index = 0; $index < $itemSize; $index++)
{
  $title = htmlspecialcharsex($arResult[$index]["TITLE"]);

  $nextRef = ($index < $itemSize-2 && $arResult[$index+1]["LINK"] <> ""? ' itemref="bx_breadcrumb_'.($index+1).'"' : '');
  $child = ($index > 0? ' itemprop="child"' : '');
  $arrow = ($index > 0? '<i class="fa fa-angle-right"></i>' : '');

  if($arResult[$index]["LINK"] <> "" && $index != $itemSize-1)
  {

  }
  else if(empty($arResult[2]))
  {
    $strReturn .= '
      <ul class="crumbs">
<li><a href="/index.php">Главная</a></li style="padding: 0 10px 0 3px;"><li style="padding: 0 10px 0 3px;"><a href="/catalog/">Каталог</a></li style="padding: 0 10px 0 3px;"><li style="padding: 0 10px 0 3px;"><a href="/catalog/new/">Вилочные погрузчики</a></li>
<li style="padding: 0 10px 0 3px;"><a href="'.$arResult[1]["LINK"].'">'.$arResult[1]["TITLE"].'</a></li>
      </ul>';
  } else
  {
    $strReturn .= '
      <ul class="crumbs">
<li><a href="/index.php">Главная</a></li style="padding: 0 10px 0 3px;"><li style="padding: 0 10px 0 3px;"><a href="/catalog/">Каталог</a></li style="padding: 0 10px 0 3px;"><li style="padding: 0 10px 0 3px;"><a href="/catalog/new/">Вилочные погрузчики</a>
                <ul class="sub-menu">'?>
<?$APPLICATION->IncludeComponent(
  "bitrix:catalog.section.list", 
  "4k2_section_breadcrumb", 
  array(
    "ADD_SECTIONS_CHAIN" => "Y",
    "CACHE_GROUPS" => "Y",
    "CACHE_TIME" => "36000000",
    "CACHE_TYPE" => "A",
    "COUNT_ELEMENTS" => "N",
    "IBLOCK_ID" => "17",
    "IBLOCK_TYPE" => "4k2_catalog",
    "SECTION_CODE" => "",
    "SECTION_FIELDS" => array(
      0 => "NAME",
      1 => "",
    ),
    "SECTION_ID" => $_REQUEST["SECTION_ID"],
    "SECTION_URL" => "#SITE_DIR#/catalog/new/#SECTION_ID#/",
    "SECTION_USER_FIELDS" => array(
      0 => "",
      1 => "",
    ),
    "SHOW_PARENT_NAME" => "Y",
    "TOP_DEPTH" => "1",
    "VIEW_MODE" => "LINE",
    "COMPONENT_TEMPLATE" => ".default"
  ),
  false
);?>
                <?'</ul>
</li>
<li style="padding: 0 10px 0 3px;"><a href="'.$arResult[1]["LINK"].'">'.$arResult[1]["TITLE"].'</a></li>
<li style="padding: 0 10px 0 3px;"><a href="'.$arResult[2]["LINK"].'">'.$arResult[2]["TITLE"].'</a></li>
      </ul>';
  }
}

$strReturn .= '<div style="clear:both"></div></div>';

return $strReturn;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question