I'm trying to implement the KeeWeb HTML file to my Laravel project.
I've tried to just add it to a blade file (e.g. keeweb.blade.php) and then using return view('keeweb'); and I'm getting the following error: Parse error: syntax error, unexpected '=', expecting ',' or ')'
However, I've also opened the HTML file with my browser and it works fine, so it seems that Blade is parsing something it shouldn't be. Fine.
So next I tried to just make a test blade file, and in that just #include('keeweb') and then rename keeweb.blade.php to keeweb.php and I get the same.
So next I tried to simply return view('keeweb'); //keeweb.php with the same error.
I need to parse some sort of variable because I need to change the head of the document so I cannot just File::get()
You are right, there are multiple occurrences of {{ in that file which Blade is trying to parse out.
I don't think you want to rename it to have only .php extension though. Try keeping it keeweb.blade.php and when you include it, try the following...
#verbatim
include('keeweb')
#endverbatim
Or even placing the #verbatim and #endverbatim inside the actual keeweb file at the top and bottom respectively, then you should be able to include it just like any other blade file.
Related
For some reason, Laravel does not parse " as expected in the footer of emails.
I am expecting to see an actual quote, but it's returning the HTML as-is.
I have tried overriding this using the toMailUsing in my AuthServiceProvider but this particular line doesn't seen to be editable.
Please advise on what I'm doing wrong.
I am trying to execute freemarker code within a freemarker ftl, I explain a little what I have:
We have a module with Spring that solves the FTL views and prints its content, even here everything works perfectly, but sometimes we will want to introduce more code in that view and we need to do it without having to deploy the module again, that is why we are entering Freemarker code in a String variable and passing that variable to the view through the model. But the problem appears here, I don't know how to manage that variable, the most I can do is paint it $ {myVar}, but the Freemakrer code appears as if it were a simple HTMl (that is, Freemarker does not execute it as such).
Is there a way to do a kind of include with that variable that has Freemarker code?
We do something alike with dymanic parts in a view. You can use interpret and <#var> to achieve that. Something like
<#assign varTempl = myVar?interpret >
<#varTempl />
The first line will parse your template, the second line will print it.
I am trying to pass a variable from Blade to a Vue component prop. However, when I'm passing the variable, something goes wrong. The error which I receive is the following:
[Vue warn]: Error compiling template:
invalid expression: Invalid or unexpected token in
[{"id":6,"name":"aaa","created_at":"2019-12-05
Raw expression: :companies="[{"id":6,"name":"aaa","created_at":"2019-12-05"
153| <!-- Page Content -->
154|
155| <company_index :companies="[{"id":6,"name":"aaa","created_at":"2019-12-05" 14:35:38","updated_at":"2019-12-05="" 14:35:38"}]=""></company_index>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
156| <!-- END Page Content -->
157| </main>
(found in <Root>)
As you can see, a random quote is added which is NOT present in the datetime itself (after 2019-12-05). It only gets added when passing it to the Vue component. Here is my code from my blade file:
#extends('layouts.backend')
#section('content')
<!-- Page Content -->
<company_index :companies={{json_encode($companies)}}></company_index>
<!-- END Page Content -->
#endsection
I've tried the following things:
Checked to see if the datetime somehow had an extra quote, this was not the case.
Checked if other Eloquent Models had the same problems, which they do (They also use standard datetimes from Laravel).
Remove json_encode from my blade file
Replaced :companies={{json_encode($companies)} with :companies={!! $companies !!}
Searched for people with the same problem, but did not find anything about this problem.
I don't think there is anything wrong with my code, but I don't know for sure what my problem is. If you need more details, just ask.
try adding double quote :companies="{{json_encode($companies)}}"
Nova was working for me before. I started working on the front-end, and when coming back to Nova it suddenly doesn't work anymore. I can log in, but then it shows the loading animation for all resources and it's not loading data.
I get this error:
Trying to get property of non-object (View: longpath/location.blade.php)
In location.blade.php
#extends('app')
#section('title')
{{ $location->title }}
#endsection
#section('content')
#endsection
The weird thing is that on the front-end, location.blade.php loads perfectly fine, as I pass the $location variable in the LocationController. No errors and nothing in the error log. In LocationController:
$location = Location::
where('id', $this->location_id)
->first();
return view('location', [
'location' => $location
]);
So it shows the error, and this error is in the logs as well. If I comment out {{ $location->title }}, it doesn't show the error anymore, but it's still not loading any data, and nothing shows up in the error log. So I have no clue why it's not loading any data. It's also a mystery to me why a (front-end) Blade template would generate an error in Nova, while it works perfectly fine on the front-end.
Update:
If I comment out this specific route in routes/web, Nova works again. Not sure why this route impacts Nova?
Route::get('/{location_id}/{location_title}', 'LocationController#viewLocation');
If I add the route back in, in my console I get:
TypeError: Cannot read property 'length' of undefined
Your route is problematic because:
Route::get('/{location_id}/{location_title}', 'LocationController#viewLocation');
is going to catch any /foo/bar URL.
If you do php artisan route:list | grep nova you'll see all of Nova's routes, and you'll find a bunch in this format:
/nova-api/metrics
/nova-api/cards
/nova-api/search
/nova-api/{resource}
etc. etc. etc.
(In other words, a bunch of Nova's routes are being sent to your LocationController instead of the right Nova controllers.)
You may be able to fix this by taking the Nova::routes call out of the app/Providers/NovaServiceProvider.php file and putting it in your routes files directly, but the cleaner solution is likely to adjust your route to be something like /locations/{location_id}/{location_title} that's not going to conflict. Wildcarded top-level routes tend to cause issues like this.
You may also be able to do this:
Route::get('/{location_id}/{location_title}', 'LocationController#viewLocation')
->where('location_id', '[0-9]+');
This will make your route only activate for numeric IDs, which means it won't interfere with the non-numeric nova-api routes.
I have saved some template tags in database, i want to process them when they are fetched from database. For instance, i have included this file in content and saved it in DB. When i fetch it just prints out in plain text.
#include('frontend.map')
Is there any way to process it? I know .blade extension is required for the engine to parse but how do we deal when the template tags and variables are saved in DB?
Blade wont support that.
What your asking is to allow Blades commands to be interpreted from supplied variables. It would actually be a massive security risk.
You'll need to have another solution that does not involve the use of Blade function calls inside your variables (database).
Perhaps have your view load a different template based upon the variable that you need?