This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
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
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>
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
1-4 of 4