在 Laravel Blade 模板中添加图像输入元素

Posted

技术标签:

【中文标题】在 Laravel Blade 模板中添加图像输入元素【英文标题】:Adding an Image Input Element in Laravel Blade Template 【发布时间】:2016-05-17 22:04:25 【问题描述】:

我想在 laravel Blade 模板中使用 input 标签上传一张图片,下面一行 ..

 Form::image('blog/images/search_btn.gif', 'button_search', ['class' => 'button_search']) 

但它在视图页面中不断显示错误

语法错误,意外的“内容”(T_STRING),应为“]”

这是我的查看页面代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>@yield('title')</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
!!Html::style('blog/style.css')!!
!!Html::style('blog/js/cufon-yui.js')!!
!!Html::script('blog/js/arial.js')!!
!!Html::script('blog/js/cuf_run.js')!!

</head>
<body>
<div class="main">
  <div class="header">
    <div class="header_resize">
      <div class="menu_nav"> 
        <ul>
          <li><a href="index.html">Home</a></li>
          <li><a href="support.html">Support</a></li>
          <li class="active"><a href="about.html">About Us</a></li>
          <li><a href="blog.html">Blog</a></li>
          <li><a href="contact.html">Contact Us</a></li>
        </ul>
        <div class="clr"></div>
      </div>
      <div class="searchform">
        <form id="formsearch" name="formsearch" method="post" action="#">

            Form::image('blog/images/search_btn.gif', 'button_search', ['class' => 'button_search']) 
          <!--   !! Html::image('blog/images/search_btn.gif', 'alt', array( 'class' => 'button_search' )) !! 
            Form::image('blog/images/search_btn.gif', 'button_search', ['class' => 'button_search]) 
          <input name="button_search" src="images/search_btn.gif" class="button_search" type="image" />-->

          <span>
          <input name="editbox_search" class="editbox_search" id="editbox_search" maxlength="80" value="Search" type="text" />
          </span>
        </form>
      </div>
      <div class="clr"></div>
      <div class="logo">
        <h1><a href="index.html">EnergyBox<br />
          <small>put your slogan here</small></a></h1>
      </div>
    </div>
  </div>
</div>
<div class="content">
  @yield('content')
  </div>
<div class="footer">
    <div class="footer_resize">
      <p class="lf">&copy; Copyright MyWebSite. Designed by Blue <a href="http://www.bluewebtemplates.com/">Website Templates</a></p>
      <ul class="fmenu">
        <li><a href="index.html">Home</a></li>
        <li><a href="support.html">Support</a></li>
        <li><a href="blog.html">Blog</a></li>
        <li class="active"><a href="about.html">About Us</a></li>
        <li><a href="contact.html">Contacts</a></li>
      </ul>
      <div class="clr"></div>
    </div>
  </div>
<div align=center>This template  downloaded form <a href='http://all-free-download.com/free-website-templates/'>free website templates</a></div>
</body>
</html>

【问题讨论】:

【参考方案1】:

您在第 31 行缺少结束 '

 Form::image('blog/images/search_btn.gif', 'button_search', ['class' => 'button_search]) 

应该是:

 Form::image('blog/images/search_btn.gif', 'button_search', ['class' => 'button_search']) 

另外,如果您正在使用 Blade,请使用 Blade 的注释语法而不是 HTML:

<!-- This is a HTML comment -->

-- This is a Blade comment, any blade code within this comment won't be parsed. --

【讨论】:

谢谢兄弟。知道了! :) 我的错误是放了错误的评论标签

以上是关于在 Laravel Blade 模板中添加图像输入元素的主要内容,如果未能解决你的问题,请参考以下文章

如何检查数据库中的图像名称并在 Laravel Blade 模板中为 NULL 时返回静态图像?

在 Laravel 5 Blade 模板中包含 SVG 内容

Laravel Blade 模板清理

请教laravel view 怎么显示 controller 中传递的对象值

Laravel之视图和Blade模板引擎

将 Laravel 中的表单值传递给 Blade 模板