0

How to check if current page is homepage? In my header i want to show something only on homepage.

$header = new ViewModel(array(
    'login' => $this->getAuthService()->hasIdentity(),
    'controller' => $this->getRequest()->getControllerName(),
    'action' => $this->getRequest()->getActionName()
    ));

In my view i have tried to find the homepage by finding index controller and index action but this is not working.

<?php
    if($this->controller = 'index' && $this->action = 'index') {
        echo 'home';
    }
    else {
        echo 'not';
    }
?>
user2406735
  • 247
  • 1
  • 6
  • 21

2 Answers2

1

You have to test if your called url is your "home" route. You cant test it by controller or action name because you could have more than one IndexController and indexAction. But you coul only have one route "home".

Stillmatic1985
  • 1,792
  • 6
  • 20
  • 39
1

Take a look at this ViewHelper or that get matched route in view.

Community
  • 1
  • 1
Stillmatic1985
  • 1,792
  • 6
  • 20
  • 39