thephpleague / plates

Native PHP template system
https://platesphp.com
MIT License
1.47k stars 180 forks source link

I can't use League\Plates\Extension\Asset; #317

Open adeilsonaalima opened 1 year ago

adeilsonaalima commented 1 year ago

Sorry for my english... anyway:

This is my controller:

<?php

namespace src\controllers;

use League\Plates\Engine;
use League\Plates\Extension\Asset;

class Web
{
    private $templates;

    public function __construct()
    {
        $this->templates = new Engine(__DIR__ . "/../views", "php");
        $this->templates->loadExtension(new Asset(__DIR__ . '/../assets/', false)); // or true
    }

    public function home(): void
    {
        echo $this->templates->render("register-and-login/home", [
            "title" => "Home | " . SITE,
            "users" => ["Adeilson", "Karol"]
        ]);
    }
}

And this is in my template:

<link rel="stylesheet" href="<?= $this->asset('/css/style.css') ?>">

If I change to a non-existent path it gives an error 500, but if it is correct it defines the following path when rendering:

<link rel="stylesheet" href="/css/style.css?v=1687988335">

And this error:

GET https://mysite.com.br/css/style.css?v=1687988335 net::ERR_ABORTED 404 (Not Found)

Why? Someone can help me?