I am building a module to show a job/vacancy-list and the detailpage of a job, the data is fetched from a remote json feed.

Currently I have the following routes to a controller in my module

return [
  'job' => 'job-offers-module/job/process',
  'job/detail' => 'job-offers-module/job/detail',

And loading twig templates eg.

namespace modules\joboffersmodule\controllers;

use Craft;
use craft\web\Controller;
use craft\web\View;

class JobController extends Controller
  protected $allowAnonymous = true;

  public function actionProcess(){
    return \Craft::$app->view->renderTemplate('joblist');
  public function actionDetail(){
    return \Craft::$app->view->renderTemplate('jobdetail');

But I keep getting an error that the entry can not be found... Do I need to register the paths in the module as a handle?

How can I load an entry from my within the module and pass it to the templates?

  • Does not answer your question, but you could consider to use feed me pro for that. – Lazy Pirate Jan 9 at 13:55

To fetch an entry from your module and pass it to a template you can do:

$entry = \craft\elements\Entry::find()->one();
return \Craft::$app->getView()->renderTemplate('path/to/template', ['entry' => $entry]);

Then in your template, you will have access to an entry variable.

|improve this answer|||||

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.