XF 2.1 Homepage for guest and homepage for register

Biarritz64

Active member
Hi
i would like to set a homepage for guest and another 1 for register.

My visitor home page will be 100% different so i don't want to use conditional statement like

<xf:if is="$xf.visitor.user_id">
Show content...
</xf:if>

Is there a way to do it?
Thank you
 
You can do this via an addon: You define a route and set this route as homepage.

In your controller you add some code like:

PHP:
    public function actionIndex()
    {
        $visitor = \XF::visitor();

        if ($visitor->user_id)
        {
             return $this->view('Dev\Addon:View', 'dev_addon_registered_view');
        }
        else
        {
            return $this->view('Dev\Addon:View', 'dev_addon_guest_view');
        }
    }

You could also show a langingpage for guests and reroute members to the forums/ route or any other route:

PHP:
    public function actionIndex()
    {
        $visitor = \XF::visitor();
        $reroutePath = 'forums/';
        $pathMatch = \XF::app()->router()->routeToController($reroutePath);

        if ($visitor->user_id && $pathMatch->getController())
        {
            $this->setSectionContext($pathMatch->getSectionContext());

             return $this->rerouteController(
                    $pathMatch->getController(), 
                    $pathMatch->getAction(), 
                    $pathMatch->getParams()
             );
        }
        else
        {
            return $this->view('Dev\Addon:View', 'dev_addon_guest_view');
        }
    }
 
Top Bottom