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 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?