XF 2.0 Template error when creating add-ons via documentation

According to the documentation I have to create a file "demo_portal_view.html" in the path "src/addons/Demo/Portal/_output/templates/public/" but when I visit the portal page it produces this error: "Template public:demo_portal_view: Template public:demo_portal_view is unknown (src\XF\Template\Templater.php:583)"

src/addons/Demo/Portal/addon.json
JSON:
{
    "title": "Demo - Portal",
    "description": "Bla bla bla...",
    "version_string": "1.0.0 Alpha",
    "version_id": 1000010,
    "dev": "You!",
    "icon": "fa-code"
}

src/addons/Demo/Portal/Pub/Controller/Portal.php
PHP:
<?php
namespace Demo\Portal\Pub\Controller;

class Portal extends \XF\Pub\Controller\AbstractController {
    
    public function actionIndex() {
        
        $viewParams = [];
        return $this->view('Demo\Portal:View', 'demo_portal_view', $viewParams);
        
    }

}

src/addons/Demo/Portal/_output/templates/public/demo_portal_view.html
HTML:
<xf:title>Portal</xf:title>



Any idea why it does not work?
 
You must create templates in the ACP. Afterwards you can just edit the corresponding files though.
 
If I create the template "demo_portal_view" in the ACP, it works, but I do not think it is a very convincing solution. The documentation does not say anything about it. If the template is part of the add-on I'm creating, I think it should be inside the add-on.
 
Then the documentation is wrong. In any case, the template should be output to your add-on directory in the appropriate location where you can make further changes (provided you associated the template with your add-on).
 
The documentation isn’t wrong.

There’s no requirement to create the template first, if the file exists on the file system it will be imported when it is requested.
 
So what is the problem? I follow the indications, as the documentation says, I create the template "demo_portal_view.html" in the path "src/addons/Demo/Portal/_output/templates/public/". The route and the controller seem to communicate with each other, but the template does not load, as if it did not exist.
 
There’s no requirement to create the template first, if the file exists on the file system it will be imported when it is requested.
Oops, I stand corrected. I've never fiddled with the default add-on setting because I switch between them often, so I had no idea it would work if you set that.

A way to have the system guess add-on associations via predefined prefixes (set in addon.json maybe?) would be cool, but I understand that belongs in a proper suggestion thread.
 
Having the add on as default is not required either.

The system already knows your add on because the template files are in your add on’s output folder.
 
Having the add on as default is not required either.

The system already knows your add on because the template files are in your add on’s output folder.

I remember getting a bit confused about how to create the template myself when reading the xf 2 dev docs. I realized more than likely it was talking about the template via the admin panel but it wasn't very clear and I actually tried copying the template code into a separate file in my confusement before I figured it out. Just wanted to mention that.
 
Oh wow, I could have sworn I tried this a long time ago and it didn't work, but I was probably just doing something silly. I didn't figure it would just scan all add-ons for the template if it wasn't found (since there would be no association). Good to know :)
 
Yea, this wasn't very clear from the docs.

The second argument is the template, which we need to create now in the path src/addons/Demo/Portal/_output/templates/public/demo_portal_view.html. That template, for now, should simply contain the following:

I just created that file on my hosting which didn't work. From this thread I realised I needed to create that template in ACP > Appearance > Templates
 
The documentation isn’t wrong.

There’s no requirement to create the template first, if the file exists on the file system it will be imported when it is requested.

I created Demo\Portal\_output\templates\public\demo_portal_view.html

I checked every code piece dozens of times.

But the portal page keeps showing me

Template errors
  • Template public:demo_portal_view: Template public:demo_portal_view is unknown (src\XF\Template\Templater.php:611)

Can you help me with this? I am going to die!
 
Top Bottom