英文:
Laravel - generate a variable dynamically using a tag of blade.php file
问题
我正在尝试向Web应用程序添加一个功能,在其中我需要将当前页面的页眉作为变量。请告诉我如何在提供页面之前在服务器上处理以下页面,并将HTML标签h2
内的文本分配给PHP变量'($currentPageHeader)'。谢谢。
<?php $currentPageHeader = "Text to be extracted"; ?>
请注意,上述代码将$currentPageHeader
设置为<h2>
标签内的文本,即"Text to be extracted"。
英文:
I'm trying to add a funtionality to a web app where I need the current page header as a variable. Could you please tell me how to process the page below in server before serving and assign the the text inside HTML tag h2
to a php variable '($currentPageHeader)'? Thank you
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<!-- Styles -->
<style>
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
<div class="content">
<div class="title m-b-md">
<h2>Text to be extracted</h2>
</div>
<div class="links">
</div>
</div>
</div>
<?php $currentPageHeader = "Text to be extracted"; ?> // Content of <h2>
</body>
</html>
答案1
得分: 1
以下是您要翻译的内容:
create master.blade.php
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<!-- Styles -->
<style>
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
<div class="content">
<div class="title m-b-md">
@yield('content')
</div>
<div class="links">
</div>
</div>
</div>
</body>
</html>
然后您可以扩展它:
@extends('master')
@section('content')
<p>This is my body content.</p>
@stop
参考链接:https://laravel.com/docs/5.0/templates#blade-templating
英文:
create master.blade.php
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<!-- Styles -->
<style>
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
<div class="content">
<div class="title m-b-md">
@yield('content')
</div>
<div class="links">
</div>
</div>
</div>
</body>
</html>
then you can extend that
@extends('master')
@section('content')
<p>This is my body content.</p>
@stop
ref link
https://laravel.com/docs/5.0/templates#blade-templating
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论