I would like to create a Nextcloud app and followed this tutorial
https://docs.nextcloud.com/server/16/developer_manual/app/intro.html
After creating the app skeleton I added some routes to routes.php
<?php
return [
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'test#index', 'url' => '/test/:value', 'verb' => 'GET'],
['name' => 'user#index', 'url' => '/user', 'verb' => 'GET']
]
];
I created some controllers by following this guide
https://docs.nextcloud.com/server/16/developer_manual/app/requests/controllers.html
My PageController.php delivers the index template
public function index() {
return new TemplateResponse('demoappct', 'index'); // templates/index.php
}
the TestController.php delivers the test template
public function index() {
return new TemplateResponse('demoappct', 'test'); // templates/test.php
}
and the UserController.php delivers the user template.
I extended the navbar.php with these routes
<ul>
<li>
<a href="#/">
Main page
</a>
</li>
<li>
Header for grouped links
</li>
<li>
<ul>
<li>
<a href="#/test/12345">
Route with param
</a>
</li>
<li>
<a href="#/user">
User Info
</a>
</li>
</ul>
</li>
</ul>
In the templates folder where index.php is I added the view files test.php and user.php.
I changed the generated index.php to
<?php
script('demoappct', 'index');
style('demoappct', 'base');
?>
<div id="app">
<div id="app-navigation">
<?php print_unescaped($this->inc('nav')); ?>
<?php print_unescaped($this->inc('settings')); ?>
</div>
<div id="app-content">
<div id="app-content-wrapper">
<?php print_unescaped($this->inc('index/content')); ?>
</div>
</div>
</div>
Please have a look at $this->inc('index/content')
. I created a content.php file for each view file I would like to render.
So test.php would call
<?php print_unescaped($this->inc('test/content')); ?>
and user.php would call
<?php print_unescaped($this->inc('user/content')); ?>
These content files are currently empty. They only contain something like
<h1>Test Page</h1>
When I test my app and click on a navigation link the routing doesn’t work. The url changes but only my index file gets rendered.
I thought that when this route 'page#test'
gets called there is a reference to the view file in the templates folder.
What am I missing?