Using the C5 router with views

Permalink
Wish to try views while routing, and am looking at https://documentation.concrete5.org/developers/routing/views... .

On this section of code directly from the documentation, Concrete\Core\View\View::setThemeHandle() is not a valid function. Concrete\Core\View\View::getThemeHandle() and Concrete\Core\Page\Theme\Theme::setThemeHandle() are both valid however, but not the one in the documentation. Please advise what needs to be changed. Also, what is the purpose of the unused $factory object?
$router->get('/account/activate', function() use ($app) {
    $factory = $app->make(\Concrete\Core\Http\ResponseFactoryInterface::class);
    $view = new \Concrete\Core\View\View(/account/activate/form’);
$view->setThemeHandle(‘green_salad’);
$contents = $view->render();
return new \Concrete\Core\Http\Response($contents);
});


Directly after this block of code, the documentation states the following:

That’s it! The HTML found at application/views/account/activate/form.php will be rendered, placed into the print $innerContent; found in application/themes/green_salad/view.php, just like what happens when working with single pages

Where are application/views/account/activate/form.php and application/themes/green_salad/view.php located? They do not exist for both my instance as well ashttps://github.com/concrete5/concrete5....

Thank you

 
NotionCommotion replied on at Permalink Reply
Please anyone. I can really use some help on this.

I have the really simple single page on the dashboard. But now I wish to add some routes which will either respond with JSON (got all that working) or return with the dashboard with the #ccm-dashboard-content-inner DIV having the appropriate HTML. I tried the router below but it is obviously worng.

Thank you for any help.

public function on_start()
    {
        $router=$this->app->make('router');
        $router->get('/dashboard/router', function(){
            //syslog(LOG_INFO, json_encode(debug_backtrace()));
            $view = new \Concrete\Core\View\View('../../packages/tester/single_pages/dashboard/main_page');
            //Only Theme has method setThemeHandle()
            //$view->setThemeHandle('green_salad');
            $themeHandle = $view->getThemeHandle(); //returns null
            //Option 1
            $app = $this->getApplication();
            $factory = $app->make(\Concrete\Core\Http\ResponseFactoryInterface::class);
            $response1 = $factory->view($view);
            //Option 2
            $contents = $view->render();



Single Page
<?php
namespace Concrete\Package\Tester;
class Controller extends \Concrete\Core\Package\Package
{
    protected $appVersionRequired = '8.2';
    protected $pkgVersion = '0.1';
    protected $pkgHandle = 'tester';
    protected $pkgName = 'Tester';
    protected $pkgDescription = 'Tester';
    public function install()
    {
        $pkg = parent::install();
        $sp = \Concrete\Core\Page\Single::add('/dashboard/main_page', $pkg);
    }
}


<?php
namespace Concrete\Package\Tester\Controller\SinglePage\Dashboard;
class MainPage extends \Concrete\Core\Page\Controller\DashboardPageController
{
    public function view()
    {
        $this->set('html', $this->getHtmlFromTwig());
        $this->render('/my_template');
    }
    public function getHtmlFromTwig()
    {
        return '<h1>Hello from single page</h1>';
    }
}


<?php
echo($html??'$html is not set');
NotionCommotion replied on at Permalink Reply
Hello again,

Anyone? If what I am asking is unclear, please let me know.

Thank you
shotrox replied on at Permalink Reply
shotrox
instead of setThemeHandle you need to use
$view->setViewTheme('green_salad');

I had a hard time getting this to work with a custom route but it works now.
However, my view.php depends on a valid page object - now I have to restructure that to enable these custom routes...

Another option I am already using is to create single pages and single page routes as they use the same page object and view as the single page itself.