如何在Laravel中存储非PHP文件的模板? [英] How to store templates for non-php files in Laravel?
问题描述
我们可以在Laravel中使用 blade
模板引擎来存储 PHP
模板文件.但是,我想在每台超过20-30行的远程服务器上创建一个配置文件.
We can store PHP
template files using blade
templating engine in Laravel. But, I want to create a config file on a remote server having more than 20-30 lines each.
到目前为止,我正在使用 Perl
进行此操作.我曾经执行过Perl文件,该文件用于将内容转储到一个文件中,并且我曾经将变量作为参数传递.
Till now, I was doing this using Perl
. I used to execute Perl file that used to dump contents in one file and I used to pass variables as parameters.
现在,我想不使用 Perl
来执行此操作.我尝试寻找解决方案,但失败了.为了易于理解,这就是我正在尝试做的事情!
Now, I want to do it without using Perl
. I tried looking for a solution but failed. To make it easy to understand, Here is what I am trying to do exactly!
我想在远程服务器上创建以下配置文件(仅作为示例).
I want to create the following config file on a remote server (Just an example).
Example.conf
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
</VirtualHost>
此处,每个配置文件中的 example.com
和 www.example.com
都会有所不同.
Here, example.com
and www.example.com
will vary in every config file.
现在,我想从laravel应用程序创建此文件到远程服务器.有什么方法可以存储此配置文件的模板,以及可以将文件编译并放置到远程服务器上?
Now, I want to create this file from my laravel application to the remote server. Is there any way I can store template of this config file and can compile and put file on remote server?
我知道如何将该文件放在远程服务器上.我只想知道存储模板并在需要时自定义模板的最佳方法.
I know how can I put this file on Remote server. I just want to know the best possible way to store template and customize it when needed.
推荐答案
您可以将其放入 blade
模板,例如 server-config.blade.php
想要将其放置在您刚刚呼叫的服务器上:
You can put it into blade
template like server-config.blade.php
and then when you want to place it on a a server you just call:
\File::put('place-on-the-server.conf', view('server-config')->render());
这将基于刀片模板生成内容(因此您可以将变量传递到此模板).
which will generate content based on the blade template (so you can pass variables to this template).
这篇关于如何在Laravel中存储非PHP文件的模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!