1

I want to render a (non-CP) template from an action method in my plugin controller over a route I defined in the plugin base class:

function registerSiteRoutes() {
  return array(
    'myservice' => array('action' => 'pluginhandle/controller/method')
  );
}

The action itself basically just sets some things up and renders the template:

public function actionMethod()
{
    // irrelevant code here...

    $variables = array('info' => 'success');
    $this->renderTemplate('pluginhandle/template', $variables);
}

But when trying to access the rendered template via it's routed url '/myservice', an error message is shown telling the template can't be found.

Strangely, it seems to work if I use the full action url actions/pluginhandle/controller/method instead. But, I want to have nice URLs if I can have them, right?

I tried it using craft()->templates->render('pluginhandle/template') and $this->renderPluginTemplate('pluginhandle/template') even temporarily setting a new templates path but none of them seems to change that.

Can someone please help me out?

1

I ended up using Jon's function renderPluginTemplate I found at https://craftcms.stackexchange.com/a/7132/6062 which basically implements what's written here: https://craftcms.com/docs/plugins/templates#plugin-template-paths-explained

I wonder why there is no easier function included into craft by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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