1

I've set up the routing for a specific URL in my plugin to trigger the actionIndex controller method. I after logging a message to the Craft logs, I want to return the rendered twig file as the view, which is supposed to look just like an empty Control Panel page. Pretty simple in theory.

Everything in the twig file seems to render just fine (text & images) except for the CSS.

Controller: Controller.php

class Controller extends \craft\web\Controller
{
    public function actionIndex(){

        Craft::info("hello!", __METHOD__);

        return Craft::$app->getView()->renderTemplate('plugin/done');
    }
}

Template: done.twig

{% extends "_layouts/cp" %}
{% set title = "Manual Sync"|t('plugin') %}

{% block content %}
    <p>Manual Sync Done.</p>
{% endblock %}

I've attached a screenshot of the elements that are rendered on the page. Screenshot of rendered elements

Hopefully that is enough for someone to help bounce some ideas around with me. Any advice and suggestions would be greatly appreciated!

1
  • Please check on your browser "network request details" window, what files are not found. If the path to your css in the template is correct, please show the part in your "_layouts/cp" file, where and how the css is included and the path of the file, that is not found.
    – phaetons
    Commented Jan 17, 2019 at 14:37

2 Answers 2

6

I sincerely appreciate the responses! I've since resolved this issue, below is the changed code. My controller was extending the Craft web controller (\craft\web\Controller) which has its own renderTemplate() method that I switched to, which fetches the Control Panel assets I wanted for styling the page.

The template twig file remains identical as is above.

(Modified) Controller: Controller.php

class Controller extends \craft\web\Controller
{
    public function actionIndex(){

        Craft::info("hello!", __METHOD__);

        return $this->renderTemplate('plugin/done');
    }
}

This did the trick for what I wanted. Thanks again!

1
  • Wow! That's a good find man! Commented Mar 12, 2020 at 11:28
2

To me it looks like something with your sites URL is wrong or your server's configuration and therefore the CSS is not loaded.

Can you take a look into your HTML-Output regarding the Links to the CSS-files? Are they linked correctly? Is both http/s?

1
  • Thank you for the response - I really appreciate Luke! That got me on the right path for looking at the \craft\web\Controller that I was extending, and I saw that it a renderTemplate() method that I actually should've been using. I've got it all working now, so I'll go ahead and post the changes I made so that hopefully someone in the future can maybe find some help from my blunders!
    – Josh Kautz
    Commented Jan 12, 2019 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.