生成一个动态变量,使用 blade.php 文件中的标签。

huangapple go评论63阅读模式
英文:

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

&lt;!doctype html&gt;
&lt;html lang=&quot;{{ app()-&gt;getLocale() }}&quot;&gt;
    &lt;head&gt;
        &lt;meta charset=&quot;utf-8&quot;&gt;
        &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;

        &lt;title&gt;Laravel&lt;/title&gt;

        &lt;!-- Fonts --&gt;
       

        &lt;!-- Styles --&gt;
        &lt;style&gt;
            
        &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div class=&quot;flex-center position-ref full-height&quot;&gt;


            &lt;div class=&quot;content&quot;&gt;
                &lt;div class=&quot;title m-b-md&quot;&gt;
                    &lt;h2&gt;Text to be extracted&lt;/h2&gt;
                &lt;/div&gt;

                &lt;div class=&quot;links&quot;&gt;
                    
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
&lt;?php $currentPageHeader = &quot;Text to be extracted&quot;; ?&gt; // Content of &lt;h2&gt;
    &lt;/body&gt;
&lt;/html&gt;

答案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

&lt;!doctype html&gt;
&lt;html lang=&quot;{{ app()-&gt;getLocale() }}&quot;&gt;
    &lt;head&gt;
        &lt;meta charset=&quot;utf-8&quot;&gt;
        &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;

        &lt;title&gt;Laravel&lt;/title&gt;

        &lt;!-- Fonts --&gt;


        &lt;!-- Styles --&gt;
        &lt;style&gt;

        &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div class=&quot;flex-center position-ref full-height&quot;&gt;


            &lt;div class=&quot;content&quot;&gt;
                &lt;div class=&quot;title m-b-md&quot;&gt;
                    @yield(&#39;content&#39;)
                &lt;/div&gt;

                &lt;div class=&quot;links&quot;&gt;

                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;

then you can extend that

@extends(&#39;master&#39;)

@section(&#39;content&#39;)
    &lt;p&gt;This is my body content.&lt;/p&gt;
@stop

ref link
https://laravel.com/docs/5.0/templates#blade-templating

huangapple
  • 本文由 发表于 2020年1月3日 19:55:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578194.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定