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

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

Laravel - generate a variable dynamically using a tag of blade.php file

问题

我正在尝试向Web应用程序添加一个功能,在其中我需要将当前页面的页眉作为变量。请告诉我如何在提供页面之前在服务器上处理以下页面,并将HTML标签h2内的文本分配给PHP变量'($currentPageHeader)'。谢谢。

  1. <?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

  1. &lt;!doctype html&gt;
  2. &lt;html lang=&quot;{{ app()-&gt;getLocale() }}&quot;&gt;
  3. &lt;head&gt;
  4. &lt;meta charset=&quot;utf-8&quot;&gt;
  5. &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
  6. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  7. &lt;title&gt;Laravel&lt;/title&gt;
  8. &lt;!-- Fonts --&gt;
  9. &lt;!-- Styles --&gt;
  10. &lt;style&gt;
  11. &lt;/style&gt;
  12. &lt;/head&gt;
  13. &lt;body&gt;
  14. &lt;div class=&quot;flex-center position-ref full-height&quot;&gt;
  15. &lt;div class=&quot;content&quot;&gt;
  16. &lt;div class=&quot;title m-b-md&quot;&gt;
  17. &lt;h2&gt;Text to be extracted&lt;/h2&gt;
  18. &lt;/div&gt;
  19. &lt;div class=&quot;links&quot;&gt;
  20. &lt;/div&gt;
  21. &lt;/div&gt;
  22. &lt;/div&gt;
  23. &lt;?php $currentPageHeader = &quot;Text to be extracted&quot;; ?&gt; // Content of &lt;h2&gt;
  24. &lt;/body&gt;
  25. &lt;/html&gt;

答案1

得分: 1

以下是您要翻译的内容:

create master.blade.php

  1. <!doctype html>
  2. <html lang="{{ app()->getLocale() }}">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <title>Laravel</title>
  8. <!-- Fonts -->
  9. <!-- Styles -->
  10. <style>
  11. </style>
  12. </head>
  13. <body>
  14. <div class="flex-center position-ref full-height">
  15. <div class="content">
  16. <div class="title m-b-md">
  17. @yield('content')
  18. </div>
  19. <div class="links">
  20. </div>
  21. </div>
  22. </div>
  23. </body>
  24. </html>

然后您可以扩展它:

  1. @extends('master')
  2. @section('content')
  3. <p>This is my body content.</p>
  4. @stop

参考链接:https://laravel.com/docs/5.0/templates#blade-templating

英文:

create master.blade.php

  1. &lt;!doctype html&gt;
  2. &lt;html lang=&quot;{{ app()-&gt;getLocale() }}&quot;&gt;
  3. &lt;head&gt;
  4. &lt;meta charset=&quot;utf-8&quot;&gt;
  5. &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
  6. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  7. &lt;title&gt;Laravel&lt;/title&gt;
  8. &lt;!-- Fonts --&gt;
  9. &lt;!-- Styles --&gt;
  10. &lt;style&gt;
  11. &lt;/style&gt;
  12. &lt;/head&gt;
  13. &lt;body&gt;
  14. &lt;div class=&quot;flex-center position-ref full-height&quot;&gt;
  15. &lt;div class=&quot;content&quot;&gt;
  16. &lt;div class=&quot;title m-b-md&quot;&gt;
  17. @yield(&#39;content&#39;)
  18. &lt;/div&gt;
  19. &lt;div class=&quot;links&quot;&gt;
  20. &lt;/div&gt;
  21. &lt;/div&gt;
  22. &lt;/div&gt;
  23. &lt;/body&gt;
  24. &lt;/html&gt;

then you can extend that

  1. @extends(&#39;master&#39;)
  2. @section(&#39;content&#39;)
  3. &lt;p&gt;This is my body content.&lt;/p&gt;
  4. @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:

确定