Change interpolation brackets - Angular2 - laravel

I want to use Laravel Blade and AngularJS.
Is some way to change interpolate sintax, change {{text}} for [{text}] or somthing like that?
I already change all components.ts files adding the line:
interpolation: ["{[", "]}"],
but, where I write blade, app breaks...
Thanks a lot everybody ;)

You can define your Blade content tags in your routes.php file:
Blade::setContentTags('<%', '%>');
Blade::setEscapedContentTags('<%%', '%%>');
EDIT: You can add # in front of the brackets, so Blade won't render it.
#{ var }
or you can pass the directive for blade not to render part of the HTML using #verbatim keyword.
#verbatim
<div>
{{ var }}
</div>
#endverbatim

Related

How can I pass a variable from slot to its layout in Laravel?

I am using Laravel 8 and I can't find a way to solve this problem.
I have a app-layout like this:
<!-- ./app-layout.blade.php -->
<html>
<head>...</head>
<body>
<livewire:create-suggestion />
{{ $slot }}
</body>
</html>
And this view uses the app-layout:
<!-- ./index.blade.php -->
<x-app-layout>
...
</x-app-layout>
In controller, I pass a variable to index view:
public function index() {
return view('index', ['variable', '$variable']);
}
How can I pass this variable to the app-layout? Because I also want to
use this in the create-suggestion livewire component.
Try this. edit your index.blade.php
#extends('app-layout', ['variable' => $variable])
...
You can pass any variable attribute to the layout like so:
<x-layout :myvariable=$myvariable>
or static attribute values like so
<x-layout myvariable="This is a string">
and retrieve it in the layout.blade.php like so:
{{ $attributes['myvariable'] }}
First off I beleive the App Layout will have access to whatever is passed by the view function. But if I am wrong or you wish to pass any custom variable whatsoever using the Layout syntaxt as opposed to template inheritance the way would be: (I came cross your question having a problem passing a static string for my HTML page title and no solution worked until I found this)
<x-app-layout>
<x-slot:variable>{{$variable}}</x-slot>
</x-app-layout>
However your issue is you are using Livewire and livewire is not simply just a view! Laravel Intentionally makes Livewire independent from the rest of the page. You would have to either pass it in PHP as param during mount which will only be accessible if set during the mount function() in \App\HTTP\LiveWire\createSuggestion.php
#livewire("create-suggestion",[ $variable])
Or ideally you have your javascript use the $emit feature to pass the element to the livewire listener all handled via Livewire. It seems to me you are using Livewire for something that you should simply only use Blade/Views:
#include("create-suggestion");

How to get route parameter from blade to vue

I have a route:
Route::get('/{my_parameter}/home', function($my_parameter) {
return view('home_view')->with('my_parameter', $my_parameter);
}
In my home_view.blade.php file:
<div>
{{$my_parameter}} {{-- displays properly --}}
<vue-component #click="doSomething( {{$my_parameter}} )">Click me</vue-component> {{-- does not work--}}
</div>
I've tried numerous variants as suggested in my searches, including #{{$my_parameter}}. When I use a hard-coded string, #click=doSomething('my_value'), the function works properly.
How do I successfully get a route parameter from blade for use in a vue component? Thank you.
I think you just forgot to add quotes around the parameter. If you have doSomething({{ $my_parameter }}) and the parameter is broccoli, it's going to turn into doSomething(broccoli) rather than doSomething('broccoli').

laravel & blade templating #section error

I want to display full name as title:
#section('title', ['title' => $userdetail->fullName])
I have used the above code and it shows the error exception of string to object conversion.
modify your #section to this
#section('title', {{$userdetail->fullName}})
#section('title', $userdetail->fullName)
You don't need to specify it as an associative array, just put variable and section will be the value of this variable
Do like this --
#section('title', "$userdetail->fullName")
Wrap the second parameter inside double quotes since it renders it automatically renders a variable and normal text, whereas single quotes only render text and not variable.
And remember that you cannot use blade echo {{ }} inside a blade syntax.
like - #section('title', {{ $userdetail->fullName }})

how to add a dynamic image src with laravels blade

My question is very simple. i use blade in laravel to show the images like
<img src="{{asset('assets/images/image.jpg')}}">
but what if my image is dynamic like:
<img src="{{asset('assets/images/$imgsrc')}}">
i cant use
<img src="{{asset('assets/images/{{ $imgsrc')}}">
because then i will end with:
<img src="http://localhost/assets/images/{{ $imgsrc">
How can i call to a $variable in a blade {{}} call?
How about
<img src="{{asset('assets/images/').'/'.$imgsrc}}">
EDIT
when you need printing more than one strings where there may be variables,functions... you need to concatenate them
Also asset('assets/images/') is equivalent to asset('assets/images') so you need to add / before printing your variable $imgsrc
Finally, in Blade {{"foo"}} is equivalent to <?php echo "foo" ?>
How can i call to a $variable in a blade {{}} call?
The normal PHP way. A blade {{}} is just the equilivant of <?php echo() ?>
So the answer to your question is:
<img src="{{ asset('assets/images/' . $imgsrc) }}">
Mine had multiple dynamic parts in the src and this is how I did it after getting in the right direction, thanks to #Laurence's answer.
<img src="{{asset('storage/'.$parentFolderName.'/'. $clientNameFolder .'/logo/').'/'.$event[0]->event_logo}}" class="event-page-country-logo">

Show blade code snippet inside a laravel blade view

I am creating documentation for my blade based components in a laravel project and would like to display syntax highlighted blade code snippets as part of the documentation a la something like this:
I have installed graham-campbell/markdown package and I try use it inside a .blade.php file as follows:
(Do not mind the escape character)
However, the output I get is as follows:
You can wrap the Blade in a #verbatim directive and use Highlight JS with a style you like
<p>You can use the laravel code template like this</p>
#markdown
```php
#verbatim
#include('components.inputs.text', [
'name' => 'input_name',
'label' => 'testing',
])
#endverbatim
```
#endmarkdown
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/styles/a11y-dark.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/highlight.min.js"></script>
<script>
hljs.initHighlightingOnLoad();
</script>
Result
Hope this helps

Resources