Laravel Blade engine does not work properly - laravel

i already uploaded my laravel 5.5 app on my host.
my problem is when i try to use
#extends('layouts.app')
#section('content')
///
#endsection
in my views, HTML works fine but blade template doesn't work.
also when I check source code with the browser I find that the "#" mark doesn't exist.
my browser source code :
extends('layouts.app')
section('content')
///
endsection
Help me ! :)

In order to work with Blade engine, make sure your view named with .blade.php extension just like Cy Rossignol mentioned in the comment. Example : home.blade.php. You can read the docs here

Related

Laravel - how to access public folder from JS file

I am using the exact same Ajax call in multiple blade templates.
If Ajax fails, I show an error jpg located in public/images/danger.png.
When I had my JS in the blade file written inline in <script> tags, it was easily accessible as I had blade helpers to access public with:
{{asset('/images/danger.png')}}
Yet now, accessing /public with:
http://"+location.host +"/public/images/danger.png
is impossible.
It would be unDRY to put the exact same AJAX call in 12 blades, no need to elaborate why..
How do you guys counter this issue?
remove /public from your route,you can directly use /images/imgname.jpg
You can just use absolute routes in your javascript files. This will however not work if your Laravel application sits in a sub folder.
"/public/images/danger.png"
just the same as used in html (in blade)
like
$('.abc').attr("src", "{{asset('imgs/male_b.svg')}}");

Writing JS code in blade templating engine

I have a Laravel 5.0 project and inside of that I have a foo.blade.php file,in here I want to use some Javascript to get the pathname of the link the user currently in like so
window.location.pathname
Is it possible? Or blade templating allows only php to be written on the file?
First, Javascript runs client side, so whatever you write in <script> tag will be totally ignored by laravel.
But if you want to access path (route) in laravel, you can check this question.

Laravel Router Not Allowing Javascript Files

I'm having a really crazy issue and I can't seem to figure it out. I've got an app that was working perfectly fine in Laravel 5.2, and I've since upgraded to Laravel 5.3. When I serve the standard view from routes/web.php and include a script tag, Laravel is trying to load the script tag as a route instead of including the file. Example:
If I add the folowing:
<script src="/js/lib/jquery.min.js"></script>
At the end of my welcome.blade.php (or index, or any of them really), I get the following in the console:
Console Error
And if I look into Sources in the Chrome devtools at the jquery file, it's loaded my same blade file as the JS file (like Laravel is trying to load it via the router). Does anyone have any hints on where I can look? I really don't want to go through the process of trying to reinstall or back out the an earlier version.
EDIT: To clarify, I've been working on this a bit, and it turns out that the app.js file will load just fine, but the js/lib/**.js files won't. I don't really know what the difference is.
How about that syntax?
<script type="text/javascript" src="{{ URL::asset('/js/lib/jquery.min.js') }}"></script>
Hope it helps you :)
That only happens when the file is not found. Check the file name again, the path and also remember pathname may be case sensitive.

Found a issue related to Laravel routing

I have issue related to Laravel routing. For example if my site is xyz.com and i have link on my home page Instagram.
Then it does not take me to the Instagram link instead of opening this link it opens the wwww.servername/laravel/public/https://www.instagram.com/myprofile/ instead. How can I open a new link?
Your link is being generated using blade functionality. However based on the discussion in the comments above, the link does not sit within a blade file, and thus the blade functionality, specifically in this case url, is not being called.
Please ensure the following:
Blade functions sit within a .blade.php file
url is called within the blade markers {{ and }}
Homepage - This will take u to homepage
This post - This will take u to your link in this case this post
Best Regards

How to add page specific JavaScript files to the Laravel Assets Pipeline?

I using Laravel Assets Pipeline(https://github.com/CodeSleeve/asset-pipeline) plugin for the my project.
I was able to successfully configure with the common JS files (jquery.js, global.js) included in the page. I have some page specific JavaScript files that needs to be included.
home.js
about-us.js
I tried with following but I think it's not the correct way to achieve this.
{{ HTML::script('assets/home.js'); }}
According to the asset-pipeline documentation it should be used like that :
<?= stylesheet_link_tag() ?>
<?= javascript_include_tag() ?>
There is a manifestFile argument which can maybe load only some specific files.
Are you sure it is compatible with HTML facade ? If it is, there is maybe a route to configure :/
And as far as I understand the documentation, you shouldn't call your script like that, one of the aim of your asset pipeline is to delegate it, isn't it ?

Resources