Answer the question
In order to leave comments, you need to log in
Assign class to div if Bitrix main page is open?
There are 2 div elements with id="one" and with id="two" how to assign classes to them if the main page of the site is open (for example, classes "red" for div with id="one" and class "green" for div with id ="two" respectively)?
I understand the condition looks like this:
<? if ($APPLICATION->GetCurPage(false) === '/'): ?>
.....
<? endif; ?>
Answer the question
In order to leave comments, you need to log in
$mainPageClass = "/" === $APPLICATION->GetCurPage(false) ? " red green " : ""
echo '<div id="one" class="someClass' , $mainPageClass, '"></div>';
Terrible way - never do that.
With this approach, you turn the content management system into a page management system.
What difference does it make what URL your page is opened at? The page should open correctly regardless of the url.
If your divs are inside this page, just give them classes.
If your divs are inside some component that is called from the page script and from other places - just add a parameter to the component in which you pass an additional class.
If your divs lie outside of the page script (I suspect that this is most likely your case), use deferred functions:
<div id="one" class="someClass <?=$APPLICATION->ShowProperty('color_class')?>">
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetPageProperty('color_class', 'green');
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question