![](/img/trans.png)
[英]Add contents of 1 file to the top of another file without overwrite in PHP?
[英]Laravel - add the contents of an HTML file to the top of another one
我有一個可以正常工作的HTML到PDF(wkhtmltopdf)的Laravel網站,用戶可以在其中修改“模板”,然后將其導出為PDF。 目前,我不得不將字體編碼為base64,因為省略了撇號等。 這本身就是大量的代碼,我不想將它們保存在數據庫中。
因此,我將以下內容存儲在blade(style.blade.php)文件中(此示例簡稱):
<style>
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 400;
src:url("data:font/ttf;base64,AAEAAAARAQAABAAQR1BPU792x2wAAS2AAAASSkdTVUKOOI56AAE/
zAAAAHBPUy8y2a6qaQAAyigAAABgY21hcIwYkAAAAMqIAAAAtGN2dCAG9xijAADScAAAAC5
mcGdtclpyQAAAyzwAAAblZ2FzcAASABgAAS10AAAADGdseWbADxfjAAABHAAAw2BoZWFk/
....
wABAAEAAmxpZ2EADmxpZ2EADgAAAAEAAAABAAQABAAAAAEACAABABoAAQAIAAIABgAMAN
YAAgBMANcAAgBPAAEAAQBJ")
format('truetype');
}
.page-break {
page-break-after: always;
}
</style>
我想將文件的全部內容“添加”到另一個HTML文件的頂部。
我如何做到這一點的任何建議將不勝感激。
非常感謝。
使用@include指令,
Blade的@include指令,可讓您輕松地從現有視圖中包含Blade視圖。
考慮你有這種看法。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>...</title>
</head>
<body>
<p>Anything could be here</p>
</body>
</html>
您想在此處include
該字體(style.blade.php)。
所以你會有類似
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>...</title>
@include('style')
</head>
<body>
<p>Anything could be here</p>
</body>
</html>
假設style.blade.php存儲在/resources/views/style.blade.php下
您可以參考https://laravel.com/docs/5.2/blade以獲取有關包含子視圖的更多信息。
您可以像以下示例那樣使內容可移植:
In Views create > content.blade.php
將您的文件內容包含在content.blade.php文件中。
然后,只要在任何需要調用這些內容的地方都可以使用以下命令將其包含在內:
@include('content') anywhere in between the code and it will act as if its present there.
通常,這是一種非常簡單的方法,當代碼重復時,我們會大量使用。 例如: Creating master blade file. Or creating header, footer etc.
Creating master blade file. Or creating header, footer etc.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.