I am using Laravel and AngularJS for my project. I changed the Angular curly brackets to {[{ because of, blade uses the same. I got some data with an $http.post() in AngularJS and I want to print this data in my views, witch I have made in Laravels blade. Because of, I am printing data from AngularJS I am using ng-repeat:
<tr ng-repeat="school in data.result">
<td>{[{ school.name }]}</td>
<td>{[{ school.brin }]}</td>
<td>{[{ school.city }]}</td>
<td>{[{ school.phonenumber }]}</td>
</tr>
This works fine. The problem is: how can I print an value inside {{ URL::to('scholen/bekijk/') }}?
Something like:
{{ URL::to('scholen/bekijk/'. {[{ school.id}]}) }}
I tried a lot, but I got errors only ;)
Something like:
{{ URL::to('scholen/bekijk/'. {[{ school.id}]}) }}
You can't.
Why? Blade is processed with PHP, which is server-side.
AngularJS processes client-side, once any/all Blade processing is completely finished.
that is because
{{ URL::to('scholen/bekijk/'. {[{ school.id}]}) }}
this code is interpret by php. but the syntax is incorrect acceding to php. because php accepts {[{ school.id}]}) part as a interpret-able php thing but its not. if u can put {[{ school.id}]}) inside the string then php is not going to interpret is because its know its just a string. but in angular side angular knows that's is a something that angular should do because the string includes {[{ school.id}]}) .
so u can try something like,
{{ URL::to('scholen/bekijk/{[{ school.id}]})' }}
You should really pick one and stick with it, by that I mean don't try and mix Blade and Angular. If you want to go with Angular pages, then make them all Angular, not some kind of Blade-Angular hybrid.
When working with Angular and Laravel I completely remove any view logic from Laravel, and use it purely as the back-end logic. Angular is responsible for all the view templating and rendering.
I suggest don't mix angular and blade...
Look at this: https://github.com/Ferticidio/UPEnews/blob/master/app/views/indexangular.blade.php only load angular...
and: https://github.com/Ferticidio/UPEnews/tree/master/public
In public i push all the angular logic...
This was very fast and comprensive for me..
Related
I want to cleanup my php file. I really like the way how blade template use curly brace to display php variables {{ $user }} https://laravel.com/docs/5.8/blade#displaying-data
Is there a way to use a functionality like that without using blade template. Using <?php echo $user ?> get's very repetitive.
This is not possible in PHP without using a template engine because it is a different syntax. Anyway in my opinion sometimes it is not the best idea to use a template engine because PHP is already kind of a template engine.
All what you seem to care about is the short syntax of echoing a variable in blade:
{{ user }}
This is as short as the syntax the PHP template engine itself provides:
<?= $user ?>
Of course Laravel (and similar) has a good reason to use template engine like blade - in order to seperate controller, logic and view (such that the view can be made by non-programmer designers for instance).
Update (thx to comments): The codes provided above do not exactly do the same as template engines (as an additional layer) may take care of e.g. escaping variables, which adds safety to the code.
As the OPs' code has already been built with echo and he is just searching for a replacement I did not mention this, but its a notable difference that you have to take care of some things yourself if not using one.
Prior to vue being part of Laravel, I would often debug by simply using {{ dump($var) }}
Doing so now throws an exception within javascript as Vue doesn't like <script> tags within the body of the content. It's not game breaking, but it is annoying. It still shows the whole array, just that the JavaScript around it doesn't work anymore.
Is there a Vue equivalent of laravel's dump? Can I tell Vue to ignore script tags when doing debugging?
To be clear, I'm looking to output the variable from PHP where it shows the properties, attributes, the type of value etc. I'm not looking to output an object within JavaScript.
console.log() will work but it will work only via javascript but i personally suggest that you will use vue.js plugin from browser? its way better to understand what is really happening on your vue variables in the back.
heres the link for
vue dev tools chrome
then on your browser(F12) u will find it from Vue tab together console,network html.
You just need to have the dump() outside the div your vue app is mounted to. So for example in your layout.blade
<body>
#yield('dump')
<div id="app">
Then in your index.blade
#extends('layout')
#section('dump')
#dump($variable)
#endsection
You can try {{ var_dump($variable) }}
If you are just looking to see the contents of the variables you are working with you can use the PHP functions var_dump() instead of dump(). It's not styled in the same sleek way that dump() is and you can't collapse or expand sections like you can with dump(). But it will dump the data you need without messing with your Vue code.
{{ dump($variable) }} without Vue:
{{ var_dump($variable) }} with or without Vue:
I'm currently making a simple file hosting script using Slim, Twig, and PHP. Right now I'm trying to append onto the current URL using Twig but am not sure how to do this. I've tried /panel/{{ newURL }} but it always just redirects me to /panel/newurl. I need to be able to dynamically update this URL.
For example, if I want to go to /tests on /panel/core/ I need to be able to append that onto the current URL. Does Twig offer a way to do this? Thanks.
Do you use Twig to render your paths? I think your application should always be able to resolve the paths, so also let the application itself render them ;-)
If that would help; you can add the parameters of the current request to the path rendering:
{{ path('yourpath', app.request.query.all|merge({'myparam': 'value'})) }}
you can use the Built-in parameter in twig {{ app.request.uri.path }}
You'll want to ensure that you've included all route and query string parameters in the URL you're appending to.
Here's an example of appending foo=bar to the current URL:
{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge(app.request.query.all)|merge({'foo': 'bar})) }}
I ended up just passing 'url' => $request->getUri()->getPath() in my view parameters. I think this is a pretty decent method because there are other methods you can call on getUri() to get different results depending on what you want to do.
I have been looking for a way to use Laravels Blade templating engine with non PHP file extensions (instead of file_name.blade.php being able to use file_name.blade.js or file_name.blade.css) to no avail. I found a post that seems to describe how to do exactly this for Laravel 4, however it no longer seems to work in Laravel 5. The reason why I would like to do this is I have a Javascript file that looks something like this:
//JS stuff
#foreach($Model->Values as $Value)
{{ $Value->name . " = " . $Value->content . ";"}}
#endforeach
//More JS stuff
And a blade/php file that looks something like this:
//Blade stuff
<script type="text/javascript">
#include('js');
</script>
And this seems to be the nicest way of passing each value to javascript. Even if there is a nicer way of passing these values to javascript, the reason behind this question is to find if there is a way to parse a non PHP file with blade as I think that could be immensely useful.
I thought View::addExtension('blade.js', 'blade') would work in L5 as well. The method hasn't changed. But do note you'll want the blade engine, not the html one like in the post you linked to. Where to put it is a good question, though. Also, you mentioned your two files have the same name before the extensions - that might screw it up, too.
I would like to remove the stripslash "\" character from my database search result.
Instead of using {{stripslashes($output->var)}}, which add a PHP function on every output in blade, can I do it GLOBALLY in the BladeCompiler file?
I want to apply this change in every output {{ }} in my Laravel site, any suggestion? I tried to modify the Bladecompiler file compileRegularEchos function, seems not working, please advice
I'm assuming you're using Laravel 5 because Blade templating defaults to escaping now. If you want to echo something without escaping you can use this syntax:
{!! $output->var !!}
For more info you can check the Blade docs