1

I have done some googling on this error I have an it seems to be an error in the blade templates but I cannot see what I have done that is different to my other templates that work. This is the error message

FatalErrorException in 66e07bb82defb1810fc6e13b82dc623493bf38fa.php line 11:
syntax error, unexpected ':', expecting '('

This is the line of code in the file that I have not touched that is showing as an error in my IDE

<?php if: ?> 

and finally here is my view that triggers the error message when I submit the form.

    @extends('templates.default')

@section('content')
<div class="col-md-6 col-md-offset-3">
            <h3>Your Account</h3>
            <form action="{{ route('profile.avatar') }}" method="post" enctype="multipart/form-data">
                <div class="form-group">
                    <label for="image">Image (only .jpg)</label>
                    <input type="file" name="image" class="form-control" id="image">
                </div>
                <button type="submit" class="btn btn-primary">Save Account</button>
                <input type="hidden" value="{{ Session::token() }}" name="_token">
            </form>
</div>
@stop

templates.default

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
    </head>
    <body>
        @include('templates.partials.navigation')
        <div class="container">
            @include('templates.partials.alerts')
            @yield('content')
        </div>
    </body>
</html>
8
  • if what? I think blade templates are expecting @if(condition) and @endif later on Commented Apr 14, 2016 at 8:42
  • @acm Hmm thanks that makes sense, I had not got that far yet was just trying to check if the upload worked. I'll try to add the conditions in now Commented Apr 14, 2016 at 8:47
  • The code triggering this error is not shown in your excerpt... I think it's located inside templates.default Commented Apr 14, 2016 at 8:55
  • @shock_gone_wild just updating the question and adding the default template file contents. It works fine when I include the templates.default in other views though Commented Apr 14, 2016 at 9:16
  • can u remove the @include('templates.partials.navigation') and try ? tell me if the probleme still exists (try that for the other one 2 ) Commented Apr 14, 2016 at 9:41

3 Answers 3

6

Forgetting to type the complete syntax expected by the directives of laravel blade template control structures can cause this. For instance the following will produce the same error that the OP came across:

@if (count($data) == 0)
    //do something
@elseif
    //do something else
@endif

while the following code does not:

@if (count($data) == 0)
    //do something
@else
    //do something else
@endif

The @elseif part expects a condition to evaluate and upon finding nothing the blade template parser goes bonkers.

Sign up to request clarification or add additional context in comments.

Comments

0

You shouldn't use anything like <?php if: ?>. If you want to use conditions inside Blade templates, do something like this:

@if($a == 2)
    A is 2
@endif

Read here for more information.

2 Comments

I wasn't using those conditions I currently have no conditions in my view but the <?php if: ?> are in a Laravel generated file located in storage\framework\views\66e07bb82defb1810fc6e13b82dc623493bf38fa.php line 11
Run php artisan view:clear to clear all views cache.
0

The function that was being called was redirecting me to another view that I had not checked, when I realised it was redirecting me upon submitting the form I then checked the view and it had a stray @if in it which was causing the error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.