XF 2.0 Cant load view?

p410n3

Member
Hello. I am currently trying to get a simple add on up and running, but I already fail at displaying a view.

I build an controller and route using this as a reference: https://xenforo.com/xf2-docs/dev/lets-build-an-add-on/

But I get a template not found:
32ddafd4e21ffafec1344abff5fbfb76.png


Code:
PHP:
<?php

//file: Pub/Controller/PrivacyController.php

namespace my\testaddon\Pub\Controller;

class PrivacyController extends \XF\Pub\Controller\AbstractController {
    function actionIndex() {
        $viewParams = [];
        return $this->view('my\testaddon:View', 'Privacy', $viewParams);
    }
}

HTML:
<!-- _output/templates/public/Privacy.html -->

<xf:title>Test</xf:title>

#0 [internal function]: XF\Template\Templater->handleTemplateError(512, 'Template public...', 'src...', 583, Array)
#1 src/XF/Template/Templater.php(583): trigger_error('Template public...', 512)
#2 src/XF/Template/Templater.php(538): XF\Template\Templater->getTemplateData('public', 'Privacy')
#3 src/XF/Template/Templater.php(1248): XF\Template\Templater->getTemplateCode('public', 'Privacy')
#4 src/XF/Template/Template.php(24): XF\Template\Templater->renderTemplate('Privacy', Array)
#5 src/XF/Mvc/Renderer/Html.php(48): XF\Template\Template->render()
#6 src/XF/Mvc/Dispatcher.php(332): XF\Mvc\Renderer\Html->renderView('my\\testaddon:...', 'public:Privacy', Array)
#7 src/XF/Mvc/Dispatcher.php(303): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#8 src/XF/Mvc/Dispatcher.php(44): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#9 src/XF/App.php(1931): XF\Mvc\Dispatcher->run()
#10 src/XF.php(328): XF\App->run()
#11 index.php(13): XF::runApp('XF\\Pub\\App')
#12 {main}
 
FWIW, we don't really use capital letters in templates. (And I know it's just a test, but worth adding a prefix to the template.)

Does your template show up in the list in the control panel?

At a guess, I'd say you haven't enabled development mode in config.php, as that is needed to pull (and push) templates from the filesystem on demand. If you create your "Privacy" template (or whatever it becomes) via the ACP, it should work -- if it doesn't, then something else is going on.
 
FWIW, we don't really use capital letters in templates. (And I know it's just a test, but worth adding a prefix to the template.)

Will remember that!

Does your template show up in the list in the control panel?

No.

At a guess, I'd say you haven't enabled development mode in config.php, as that is needed to pull (and push) templates from the filesystem on demand. If you create your "Privacy" template (or whatever it becomes) via the ACP, it should work -- if it doesn't, then something else is going on.

It is enabled, though I havent added an default add on.

Well but as you are not able to spot any error on my code, I will just reinstall my local env. I'll give an update if / when it works

Thanks for helping out

EDIT: forgot to mention, it works after manually creating a template. How would that work when I would actually release that add on. can i create a template via setup.php?
 
You would assign your template to your addon. This will import the template on setup.

I am struggling to follow ou on this one.

What I was trying to say is: I wanna "release" my add-on to a new forum. So do I manually have to assign the template (and route for that sake) in the admin cp or can i do both via setup.php. As this plugin might be rolled out to multiple forums, I kinda wanna save the time to do the installs.

How about directly adding them to the DB using the sheme manager?
 
You create them in the master style with development mode enabled and assign them to your add-on directly on the edit page. XenForo then automatically bakes them into your zip when you build it through the CLI.
 
You create them in the master style with development mode enabled and assign them to your add-on directly on the edit page. XenForo then automatically bakes them into your zip when you build it through the CLI.

Thats cool. Thanks for all the help!
 
Back
Top Bottom