从数据库存储的字符串扩展刀片模板 [英] Extend Blade Template from Database stored string

查看:75
本文介绍了从数据库存储的字符串扩展刀片模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我需要将字符串作为参数传递给view,其中包含要呈现的Blade Template标签.我已经完成了研究,并且我相信所问的其他问题与我的无关.因此,以下是我要实现的目标.

My problem is that I need to pass string as an argument to view, which contains the Blade Template tags to be rendered. I've done my research and I believe the other problems asked don't relate to mine. Hence following is what I want to achieve.

我想从数据库中检索主布局,并从中检索子视图.因此,在我的情况下,需要从数据库中的字符串扩展要传递给 view()方法的视图.

I want to retrieve the master layout from database and extend the child views from it. So in my case, the view that is to be passed to view() method needs to be extended from a string in database.

因此在page.blade.php中应该可以使用以下内容

So something like the following should work in page.blade.php

@extends("<html>@yield('content')</html>") ---> the string shall be passed from database.
@section('content')
...
...
@endsection

或者 Controller 本身的其他一些代码也可以,例如我首先调用主布局,然后将其传递给子视图,以替换'content'部分.

Or some other code from the Controller itself may be okay, such as I call for the main layout first, then pass it the child view, which replaces the 'content' section.

推荐答案

考虑到社区的热烈反响,即使有很多意见,我还是决定寻求解决方法,直到找到更好的解决方案. (讽刺意向)

Well, considering the over-whelming response from the community even after many views, I decided to go for a work-around, until I find a better solution. (Sarcasm intended)

在此处进行记录,以便为可能会尝试这样做的人提供线索.

Documenting it here, so as to give a clue to those who might be trying the same.

  1. 从主视图扩展子视图(例如 db_master.blade.php )
  2. 在您的控制器中,使用任一数据库列中的内容放入主视图 ( db_master.blade.php ) FileSystem 类或 file_put_contents (无论您觉得有多安全).
  3. 现在照常返回子视图.
  1. Extend the child view from a master view (say db_master.blade.php)
  2. In your Controller, put contents from the database column into the master view (db_master.blade.php) using either FileSystem class or file_put_contents (whatever you feel more secure with).
  3. Now return the child view as usual.

注意:确保将安全代码传递到主视图(也就是说,请注意使用户能够访问刀片模板引擎,因为他们可以注入实际的php代码)

Note: Make sure you pass secure code to the master view (that is, take care of giving users access to blade templating engine, as they can inject actual php code)

请提供反馈和建议.

这篇关于从数据库存储的字符串扩展刀片模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆