问题标签 [laravel-blade]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
31 回答
443399 浏览

php - 如何在 Laravel Blade 模板中设置变量

我正在阅读 Laravel Blade文档,但我不知道如何在模板中分配变量以供以后使用。我不能这样做{{ $old_section = "whatever" }},因为那会呼应“随便”,我不希望那样。

我知道我可以做到<?php $old_section = "whatever"; ?>,但这并不优雅。

在 Blade 模板中是否有更好、更优雅的方式来做到这一点?

0 投票
14 回答
184547 浏览

php - 在 Laravel 刀片模板中截断字符串

Laravel 中的刀片模板是否有截断修饰符,很像 Smarty?

我知道我可以在模板中写出实际的 php,但我正在寻找更好的东西来编写(让我们不要进入整个 PHP 是模板引擎的辩论)。

所以例如我正在寻找类似的东西:

我知道我可以通过作曲家使用 Twig 之类的东西,但我希望 Laravel 本身具有内置功能。

如果没有,是否可以创建自己的可重用修饰符,如 Smarty 提供的。我喜欢 Blade 不会过度使用所有语法这一事实,但我认为 truncate 是一个真正方便的功能。

我正在使用 Laravel 4。

0 投票
4 回答
54424 浏览

php - Laravel - 语法错误,文件意外结束

我有一个在主机上运行良好的网站,但我目前正在尝试将它安装在 localhost 上。

我已经下载了所有内容并配置为在 localhost - 数据库和 URL 上工作。

问题是这个错误:

未处理的异常

信息:

语法错误,文件意外结束位置:

C:\Program Files (x86)\EasyPHP-12.1\www\laravel\view.php(386) : eval()'d 代码在第 118 行

而且我不知道是什么原因造成的。有什么解决办法吗?

PS 我已经在我的 Windows 主机文件中设置了127.0.0.1 myproject.dev

0 投票
7 回答
26257 浏览

php - 有没有办法从字符串编译刀片模板?

如何从字符串而不是视图文件编译刀片模板,如下面的代码:

http://paste.laravel.com/ujL

0 投票
3 回答
5186 浏览

wordpress - 是否可以在视图文件夹之外使用 laravel 刀片?

我在公共子文件夹中有一个 wordpress 博客。

我想使用与使用刀片的 laravel 视图相同的布局。

有没有办法做到这一点?

0 投票
4 回答
53482 浏览

laravel - Laravel 4 Helpers 和基本函数的最佳实践?

我试图了解在 Laravel 4 中放置全局函数的最佳位置。例如,日期格式。我不认为做一个门面是值得的,因为门面太模块化了。我已经阅读了有关创建库文件夹并在其中存储类的文章,但这对于一个简单的函数来说似乎也很多。Blade模板中不应该有这样的“工具”吗?

像这样的最佳实践是什么?我如何使它可用于 Blade 模板?

0 投票
29 回答
494125 浏览

laravel - 如何在 Laravel 4 中的 @if 语句(刀片)中获取当前 URL?

我正在使用 Laravel 4。我想@if使用 Laravel 的 Blade 模板引擎在视图中访问条件内的当前 URL,但我不知道该怎么做。

我知道它可以使用类似的东西来完成,但是在刀片语句中<?php echo URL::current(); ?>是不可能的。@if

有什么建议么?

0 投票
2 回答
2087 浏览

javascript - Dynamically change div CSS background using JS within blade foreach loop

I am trying to display user created images on a photos.index view using Laravel 4. As you can see below I am using foreach to go through those pictures. However, as I want to have them displayed in boxes 300px height and 300px width I am using the css background method "cover" in my "box" class.

Now I hav to use JS to change the background image of every box according to what is inserted in the database.

The code below gives me the following result: There are as much boxes displayed as I have in my database. However, they all have the same picture, more exactly the picture that is the last one in the database.

Now my question is: What do I have to do to change the background image for each box individually?

It could be important to know that those JavaScripts I see if I open the site with Developer Tools DO have the correct link to the picture that should be displayed. However, the CSS background of every div is always the last picture in the DB.

0 投票
0 回答
462 浏览

php - Laravel 4 和 Blade - 依赖于变量的部分

我在使用 Blade 和 Laravel 4 时遇到了一个严重的问题,特别是我需要有一个部分来改变它的内容,这些变量由父部分处理。

举个例子,看看那个

控制器.php

用户列表.blade.php

base-list.blade.php

问题是我得到了未定义$row的变量,因为用户列表模板在基本列表模板之前被解析并执行。

为了解决我所做的问题:

base-list.blade.php

基本列表-row.blade.php

但是,说真的,我看不到那个:\

因为在使用 @extends 时模板是从子级渲染到父级的,所以我什至无法使用该$__env->share('row', $row)技巧,因为子级在父级之前执行。

有人有解决方案或更好的解决方法吗?

0 投票
3 回答
2185 浏览

laravel - 刀片模板的替代品

我是 Laravel 的新手,我已经厌倦了我正在做的项目。到目前为止,最烦人的事情是刀片模板。有没有我可以使用的替代品?