0

am try to echo blade html tag but it error.

help me for check my code please

echo "<td><a href="{{ URL::to('index/watch/$tmpd') }}">$tmpd</a></td>";

variable tmpd is value for my loop

From comments

Trying to echo this from within a foreach loop:

foreach ($words as $row) { 
    echo '<tr>';
    $tmpd = $row['title'];
    echo "<td><a href='watch/$tmpd'>$tmpd</a></td>";
}
4
  • syntax error, unexpected '{', expecting ',' or ';' Commented Apr 29, 2016 at 10:14
  • Try like this: <td><a href="{{ URL::to('index/watch/$tmpd') }}">{{ $tmpd }}</a></td> Commented Apr 29, 2016 at 10:16
  • not work but i use <td><a href="{{ URL::to('index/watch/' . $tmpd) }}">{{ $tmpd }}</a></td> it work Commented Apr 29, 2016 at 10:25
  • sinle quote will not be interpreted Commented Apr 29, 2016 at 10:42

2 Answers 2

1

Assuming this is a view file try

<td><a href="{{ URL::to('index/watch/' . $tmpd) }}">{{ $tmpd }}</a></td>

From the comments you are within a foreach loop. Using blade this should be something like:

@foreach($words as $row)
    <tr>{{ $row['title] }}
        <td><a href="{{ url('watch/' . $tmpd) }}">{{ $tmpd }}</a></td>
    </tr>
@endforeach

With blade syntax like this you can remove this syntax from within any <?php ?> php tags you have.

My suggestion would be to look at the blade syntax documentation.

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

6 Comments

not work yntax error, unexpected '{', expecting ',' or ';'
tmpd is my variable it look like string i want to add to url
if i change to echo "<td><a href='watch/$tmpd'>$tmpd</a></td>"; it work but
foreach ($words as $row) { echo '<tr>'; $tmpd = $row['title']; echo "<td><a href='watch/$tmpd'>$tmpd</a></td>";
i want to use herf with blade
|
0

You cannot use variables inline when using apostrophes, e.g. 'Href: $href' will not work. You have to use quotes for that or add a variable separately.

Also, blade has foreach loop, which will make your templates more readable. Try this:

@foreach($words as $row)
    <tr><td><a href="{{ url('watch/' . $row['title']) }}">{{ $row['title'] }}</a></td>
@endforeach

If you are still getting errors, check other code in the same template - maybe you forgot to close a statement somewhere or something.

1 Comment

i try to use echo "<td><a href="{{ url('watch/' . $row['title']) }}">{{ $row['title'] }}</a></td>"; but syntax error, unexpected '{', expecting ',' or ';'

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.