This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

rmiller63803
rmiller63803

I can't seem to find this in the documentation. I have a backend controller:

<?php

namespace Velitalia\RaceScraper\Controllers;

use Illuminate\Support\Facades\Log;
use Velitalia\RaceScraper\Models;

// =============================================================================
class Races extends \Backend\Classes\Controller {
    // =========================================================================
    public function index() {
        Log::info("In Race.php index");

        $this->vars["schedule"] = Models\RaceSchedule::with("race")->get();
        Log::info(json_encode($this->vars["schedule"], JSON_PRETTY_PRINT));
    }

    // =========================================================================
    public function onStart() {
        $this["foo"] = "able baker";
    }
}
... and then in directory races under the same controllers directory, I have:
url = "/backend/velitalia/racescraper/races/index"

[Races]

==

==

{{ foo }}

<table>
    <?php
    foreach($schedule as $race) {
        echo("<tr>");
            echo("<td>" . $race->year . "</td>");
            echo("<td>" . $race->race->name . "</td>");
        echo("</tr>");
    }
    ?>
</table>
...

It's processing the php as php, but the whole template is output, with {{ foo }} included as a literal. How do I tell October CMS I want this .htm to be interpreted as a TWIG template?

Thanks, Bob

Last updated

rmiller63803
rmiller63803

Sorry, didn't realize that would be so ugly. Here goes again ...

I can't seem to find this in the documentation. I have a backend controller:

<?php

namespace Velitalia\RaceScraper\Controllers;

use Illuminate\Support\Facades\Log;
use Velitalia\RaceScraper\Models;

// =============================================================================
    class Races extends \Backend\Classes\Controller {
    // =========================================================================
    public function index() {
        Log::info("In Race.php index");
        $this->vars["schedule"] = Models\RaceSchedule::with("race")->get();
        Log::info(json_encode($this->vars["schedule"], JSON_PRETTY_PRINT));
    }

    // =========================================================================
    public function onStart() {
        $this["foo"] = "able baker";
    }
}

... and then in directory races under the same controllers directory, I have index.html: url = "/backend/velitalia/racescraper/races/index"

[Races]

==

==

{{ foo }}

<table>
    <?php
    foreach($schedule as $race) {
        echo("<tr>");
            echo("<td>" . $race->year . "</td>");
            echo("<td>" . $race->race->name . "</td>");
        echo("</tr>");
    }
    ?>
</table>
daftspunky
daftspunky

Twig doesn't work natively in the backend, you just use PHP as a simple templating engine. Check out some other plugins to see how this works

rmiller63803
rmiller63803

Okay, thanks. I thought I saw something that suggested it would work.

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.