我通过TWIG模板在HTML中导入CSS样式表有问题。asset()函数似乎不能被编译器识别。css文件在app/views/styles中,login.html在app/views中。出现以下错误:
Unknown "asset" function.
index . php
<?php
declare(strict_types=1);
require '../vendor/autoload.php';
use SlimFactoryAppFactory;
use SlimViewsTwig;
use SlimViewsTwigMiddleware;
$app = Appfactory::create();
//twig
$percorso= __DIR__ . '/../app/views';
$twig = Twig::create($percorso, ['cache' => false]);
$app->add(TwigMiddleware::create($app, $twig));
//middleware
require '../app/middleware.php';
$app->addErrorMiddleware(true, true, false);
//rotte
require '../app/routers/routes.php';
// Run app
$app->run();
login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{asset('styles/styleguide.css')}}">
</head>
<body>
<div class="overlap-group">
<div class="over">
<div class="centered-text-home">
<h1 class="title">GREPPINOTES</h1>
<img src="assetsedit@1x.png" class="edit">
</div>
<h1 class="subtitle-home">La serietà dello studio, il piacere dello studio</h1>
<div class="centered-button-home">
<button type="button" class="btn btn-primary btn-rounded ">ACCEDI AL SITO</button>
</div>
</div>
</div>
</body>
</html>
composer.json
{
"require": {
"slim/slim":"4.*",
"slim/psr7": "^1.5",
"selective/basepath": "^2.1",
"slim/twig-view": "3.3",
"symfony/asset": "^5.4"
},
"autoload": {
"psr-4": {
"App\": "app/",
"App\Controller\": "app/controllers/",
"App\Auth\": "app/middleware/"
}
}
}
我使用的是twig-view 3.3和symfony 5.4。
我试图通过在HTML中添加<style>
块来导入样式,并且它工作了,但我想使用不同的文件只是为了样式。
运行composer require symfony/webpack-encore-bundle然后运行npm install
运行composer require symfony/webpack-encore-bundle然后运行npm install然后运行npm Run dev