0

I using laravel 4 and typeahead.js, but get error message becouse the {{}} delimiters are the same of the JQuery.

 <script type="text/javascript"> 
  jQuery(document).ready(function($) {
  $('#pessoa_id').typeahead([
   {
     name: 'planets',
     remote: '/sistema/lancamento/pessoa/%QUERY',
     template: '<p><strong> {{pessoa_id}} </strong> – {{nome}} </p>',
  ]);

Any sugestion ?

Thanks. Helder

helderam
  • 37
  • 1
  • 7
  • While I answered below, this is something of a duplicate of http://stackoverflow.com/questions/20432935/laravel-4-blade-and-hogan-js-syntax – Nathan Loding Dec 09 '13 at 01:17

3 Answers3

9

You can change the delimiters as montogeek suggests, but it's probably easiest to just prepend it with an @ symbol.

<script type="text/javascript"> 
  jQuery(document).ready(function($) {
  $('#pessoa_id').typeahead([
   {
     name: 'planets',
     remote: '/sistema/lancamento/pessoa/%QUERY',
     template: '<p><strong> @{{pessoa_id}} </strong> – @{{nome}} </p>',
  ]);

Laravel will not try to parse it.

http://laravel.com/docs/templates#other-blade-control-structures

Nathan Loding
  • 3,185
  • 2
  • 37
  • 43
1

You can change the delimiters of Blade in the controller or in a route

Route::get('/', function()
{
    Blade::setEscapedContentTags('[[', ']]');
    Blade::setContentTags('[[[', ']]]');

    return View::make('home');
});

That will change the delimiters that use Blade for that view.

Hope that helps!

Fernando Montoya
  • 2,625
  • 1
  • 18
  • 21
0

You can use Json syntax within a blade file, only {{ }} and {{{ }}} are used to evaluate PHP..

But you do have some badly formatted Json which is probably causing your bracket miss match problem.

[{
    name: "planets",
    remote: "/sistema/lancamento/pessoa/%QUERY",
    template: "<p><strong> {{pessoa_id}} </strong> – {{nome}} </p>"
}]

EDIT:

After looking at typeahead.js I see that you will need to change delimiters as per @montogeek answer too.

Wader
  • 9,427
  • 1
  • 34
  • 38