XF 2.1 Get no html view on route page

emiya

Member
Hello,

I'm learning programming and want to create an addon which have it's own page. Everything is good so far, but on the page html won't work?
view.png

Well, I created a new route with following inputs:
routes.png

And that's the code (/src/addons/NewAddon/NewPage/Pub/Controller/NewPage.php):

PHP:
<?php

namespace NewAddon\NewPage\Pub\Controller;

use XF\Mvc\ParameterBag;
use XF\Pub\Controller\AbstractController;

class NewPage extends AbstractController
{
    public static function somehow()
    {
    
        //some codes ..
    
        return $text = "You will be redirected ... <br />Blabla <a href='https://theurl.com/andstuff'> or click here!</a>.";

    }

    public function actionIndex(ParameterBag $params)
    {
        return $this->message($this->somehow());
    }
}

What did I wrong? Thanks in advance and kindly regards
 
Last edited:
One approach: Replace your $text with a phrase. Phrases support HTML (though HTML should be used in templates, and not phrases).

return \XF::phrase('your_phrase_prefix_you_will_be_redirected_blabla');

Another approach (the better one) is to set the message in viewParams, and expose that to your template. In the template you can use |raw
 
Last edited:
Thank you @Lawrence, it worked. However, I still have a problem.

The url is random and I want to use the variable on this phrase. How can I do that?

PHP:
return $text = "You will be redirected ... <br />Blabla <a href='{$url}'> or click here!</a>."; // I need this variable
 
Thank you @Lawrence, it worked. However, I still have a problem.

The url is random and I want to use the variable on this phrase. How can I do that?

PHP:
return $text = "You will be redirected ... <br />Blabla <a href='{$url}'> or click here!</a>."; // I need this variable
$url = 'the url you want to use';

\XF::phrase('your_phrase_prefix_you_will_be_redirected_blabla ', ['url' => $url]);

your phrase text:

You will be redirected ... <br />Blabla <a href="{url}"> or click here!</a>.
 
Top Bottom