A
A
Alexey Kravchinsky2020-03-08 14:28:31
Yii
Alexey Kravchinsky, 2020-03-08 14:28:31

How to check if the main page of the site in yii2?

how to check if the main page of the site?
to render one header on the main page, and a 2 header on other pages

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
smigles, 2020-03-08
@smigles

You can declare a variable in the main page view, for example: Further in the template:
$this->params['isHome'] = true;

<?php if (isset($this->params['isHome'])): ?>
<header>
    ...
</header>
<?php else: ?>
<header>
    ...
</header>
<?php endif ?>

You can also use different templates, see the documentation .
If your main page header is not used anywhere else, then it would be logical not to make a second template, but to move this header to the main page view, and disable the generation of a common header in the template:
<?php if (!isset($this->params['isHome'])): ?>
<header>
    ...
</header>
<?php endif ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question