dre26973 2015-07-27 21:23
浏览 46
已采纳

如何在laravel 5中的刀片模板中创建变量以供部分视图使用

I created a partial view which have a common form code. What I want to do it to change the value of the button, so I thought I would just create a variable in the parent view and just before @include the partial view I would set a variable which then the partial view use to display the correct title.

Here is my partial view code

  <div class="form-group">
    {!! Form::label('account_name_id', 'Account Name', ['class' => 'col-sm-2 control-label' ]) !!}
    <div class="col-sm-10">
      {!! Form::text('account_name', null, ['class' => 'form-control', 'id' => 'account_name_id', 'placeholder' => 'Account Name...']  ) !!}
    </div>
  </div>



  <div class="form-group">
    {!! Form::label('legal_name_id', 'Legal Name', ['class' => 'col-sm-2 control-label' ]) !!}
    <div class="col-sm-10">
      {!! Form::text('legal_name', null, ['class' => 'form-control', 'id' => 'legal_name_id', 'placeholder' => 'Legal Name...']) !!}
    </div>
  </div>



  <div class="form-group">
    {!! Form::label('company_code_id', 'Company ID', ['class' => 'col-sm-2 control-label' ]) !!}
    <div class="col-sm-10">
      {!! Form::text('company_code', null, ['class' => 'form-control', 'id' => 'company_code_id', 'placeholder' => 'Company Identifier...']  ) !!}
    </div>
  </div>



  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      {!! Form::submit($submitButtonTitle, ['class' => 'btn btn-primary']) !!} 
    </div>
  </div>

please note the $submitButtonTitle variable in my partial view above.

Then in the parent view I have done something like this

@extends('layouts.master')
@section('main')

    {!! Form::open(['route' => ['account_store_path'], 'class' => 'form-horizontal']) !!}

  {{ $submitButtonTitle = 'Add Account' }}
  @include ('accounts._form')

    {!! Form::close() !!}
@stop

The problem that I am having is I am not sure how to set variable without displaying it on the screen.

when I do

  {{ $submitButtonTitle = 'Add Account' }}

it actually sets the variable correctly but it also echo it to the screen. How can I only set the variable without echoing it to the screen?

  • 写回答

2条回答 默认 最新

  • dongya767979565 2015-07-27 21:42
    关注

    This is a proper blade inclusion. You can add the partial to your view in this way:
    @include('your_partial', ['submitButtonTitle' => 'Add Account'])

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛