如何将JS/CSS文件包含到Slim Framework的模板中?

编程入门 行业动态 更新时间:2024-10-10 06:21:19
本文介绍了如何将JS/CSS文件包含到Slim Framework的模板中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Slim框架开发一个简单的Web应用程序.我陷入了一个可能简单的问题.我想在模板中包含静态文件(CSS和Javascript).

I am developing a simple web app with Slim framework. I got stuck with a probably simple problem. I want to include static files (CSS and Javascript) into my template.

我的项目文件夹结构如下:

My project folder structure is as follows:

index.php //<=== where all the routing happens. /flot layout.css jquery.js .... /templates first_template.php

first_template.php的标头包含:

My header of first_template.php contains:

<link href="../flot/layout.css" rel="stylesheet" type="text/css"> <script language="javascript" type="text/javascript" src="../flot/jquery.js"></script>

当我调用项目的根URL

When I call the projects root url

localhost/xampp/ProjectX/

(我正在使用XAMPP)显示了模板,但是CSS和javascript内容无法正常工作. Google Chrome控制台显示:

(I'm using XAMPP) the template shows up, but the css and javascript stuff is not working. The Google Chrome console shows:

GET localhost/xampp/ProjectX/flot/layout.css 404 (Not Found) GET localhost/xampp/ProjectX/flot/jquery.js 404 (Not Found)

有什么建议吗?我花了整整一个小时在谷歌搜索上,但是Slim框架的整体文档实际上还很薄:)

Any suggestions? I spent almonst one hour in googling, but the overall documentation of the Slim framework is still literally slim :)

推荐答案

我假定您正在项目根目录(index.php)上显示模板,因此应从样式表和JS相对路径中删除../:

I assume you are displaying your Template on the Project root (index.php), so you should remove the ../ from your Stylesheet and JS relative Paths:

<link href="flot/layout.css" rel="stylesheet" type="text/css"> <script language="javascript" type="text/javascript" src="flot/jquery.js"></script>

更多推荐

如何将JS/CSS文件包含到Slim Framework的模板中?

本文发布于:2023-11-28 19:58:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643761.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   模板   文件   JS   CSS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!