indersein's avatar

For laravel blade with handlebars

How to set if condition in my href link please help me anyone

    <div class="dropdown">
        <button type="button" class="btn btn-xs btn-primary dropdown-toggle" data-toggle="dropdown">
            <i class="fa fa-cog" aria-hidden="true"></i>
            </button>
        <div class="dropdown-menu">
            <form method="post" action="/admin/automations/@{{id}}/destroy">
                <input type="hidden" name="_token" value="{{$csrf_token}}"/>
                <button class="dropdown-item" type="submit">Delete Automation</button>
            </form>
        </div>
        <a class="btn btn-xs btn-primary" href="/admin/automations/disable/@{{uuid}}/@{{ status }}">@{{ status }}</a>
      </div>
</script>
0 likes
9 replies
mvd's avatar

Hi @indersein

Try something like this

@if(your_if_statement_here)
<a class="btn btn-xs btn-primary" href="your_link_address">@{{ status }}</a>
@else
<a class="btn btn-xs btn-primary" href="your_second_link_address">@{{ status }}</a>
@endif
indersein's avatar

Don't work syntax error, unexpected '<' (View:

Same error

Snapey's avatar

What is it you are trying to do?

indersein's avatar

@section('title', 'Forms')

@section('content_header')
@stop

@section('content')
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">Forms</h3>
                @if (Auth::user()->can('create-forms'))
                <a class="btn btn-primary float-right" href="{{url('admin/form/create?i=form')}}">Add New Form</a>
                @endif
            </div>

            <!-- /.card-header -->
            <div class="card-body">

                <form class="form-inline-custom container-filter">
                    <div class="form-group">
                        <select class="form-control input-sm" id="forms-dt-filter-status">
                            <option value="" selected>Status - All</option>
                            <option value="Draft">Draft</option>
                            <option value="Active">Active</option>
                            <option value="Disabled">Disabled</option>
                        </select>
                    </div>
                </form>

                <table class="table table-bordered table-hover dataTable" data-module="forms-dt">
                    <thead>
                        <tr>
                            {{-- <th>ID</th> --}}
                            <th>Title</th>
                            <th>Updated</th>
                            <th>Created</th>
                            <th>Status</th>
                            <th class="action">Action</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div>
</div>
@stop

@section('page_js')
<script>
    $(function(){

$.fn.formsDt = function(userOptions) {
  var self = this;

  if ($.type(userOptions) === 'string') {
    userOptions = { url: userOptions };
  };

  var options = $.extend({
    url: 'v1/admin/forms'
  }, userOptions);

  self.dt({
    url: options.url,
    order: [[0, 'desc']],
    columns: [
      {
        name: 'title',
      },
      {
        name: 'updated_at',
        className: 'datetime',
        formatter: 'dateTimeLong'
      },
      {
        name: 'created_at',
        className: 'datetime',
        formatter: 'dateTimeLong'

      },
      {
          name: 'status',
          className: 'status',
          template: $.compile('@{{ formStatus this }}')
      },
      {
        name: 'actions'
      }
    ]
  });

  $('#forms-dt-filter-status').on('change', function (e) {
        self.dtSearchColumn(1, $(this).val());
  });

  return self;
};

$('[data-module=forms-dt]').formsDt();
});
</script>

<script type="text/x-handlebars-template" data-template="forms-dt-actions">
    <div class="dropdown">
        <button type="button" class="btn btn-primary btn-xs dropdown-toggle" data-toggle="dropdown">
            <i class="fa fa-cog" aria-hidden="true"></i>
            </button>
        <div class="dropdown-menu">
            <a class="dropdown-item" href="/admin/form/@{{uuid}}/edit?i=form">Edit</a>
        </div>
      </div>
      <a class="btn btn-xs btn-primary" href="/admin/form/@{{uuid}}/active">Activate</a>
</script>
@stop



This is my full code
indersein's avatar
    <div class="dropdown">
        <button type="button" class="btn btn-primary btn-xs dropdown-toggle" data-toggle="dropdown">
            <i class="fa fa-cog" aria-hidden="true"></i>
            </button>
        <div class="dropdown-menu">
            <a class="dropdown-item" href="/admin/form/@{{uuid}}/edit?i=form">Edit</a>
        </div>
      </div>
      <a class="btn btn-xs btn-primary" href="/admin/form/@{{uuid}}/active">Activate</a>
</script>

I want to put an if condition here.
mt_dev's avatar

Hello @indersein

Can you please let me know, How you had resolve the error?

I am facing the same issue in this.

When I am trying to apply the if else condition, getting syntax error.

<script id="details-template" type="text/x-handlebars-template">
    <table class="table">
        <tr>
            <td>@{{ name }}</td>
            <td>@{{ image }}</td>
            <td>
                {{#if status}}
      <img src="star.gif" alt="Active">
    {{else}}
      <img src="default.gif" alt="default">
    {{/if}}
            </td>
            
        </tr>
    </table>
</script>

Laravel with handlebars-template

thinkverse's avatar

@mt_dev Don't resurrect a 2-year-old thread with your issue, create your own thread instead.

Please or to participate in this conversation.