blade

Laravel 4 Blade @include variable

纵饮孤独 提交于 2019-12-03 14:38:43
问题 I was trying to do include with Laravel blade, but the problem is it can't pass the variable. Here's my example code: file_include.blade.php <?php $myvar = "some text"; main.blade.php @include('file_include') {{$myvar}} When I run the file, it return the error "Undefined variable: myvar". So, how can I pass the variable from the include file to the main file? Thank you. 回答1: Why would you pass it from the include to the calling template? If you need it in the calling template, create it there

how to add a dynamic image src with laravels blade

喜欢而已 提交于 2019-12-03 13:51:33
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(

Creating custom error page in Lumen

只谈情不闲聊 提交于 2019-12-03 13:13:33
问题 How do I create custom view for errors on Lumen? I tried to create resources/views/errors/404.blade.php , like what we can do in Laravel 5, but it doesn't work. 回答1: Errors are handled within App\Exceptions\Handler . To display a 404 page change the render() method to this: public function render($request, Exception $e) { if($e instanceof NotFoundHttpException){ return response(view('errors.404'), 404); } return parent::render($request, $e); } And add this in the top of the Handler.php file:

Check if a view exists and do an @include in Laravel Blade

只谈情不闲聊 提交于 2019-12-03 13:03:32
With Laravel Blade, is there an elegant way to check if a view exists before doing an @include ? For example I'm currently doing this: @if(View::exists('some-view')) @include('some-view') @endif Which gets quite cumbersome when 'some-view' is a long string with variables inside. Ideally I'm looking for something like this: @includeifexists('some-view') Or to make @include just output an empty string if the view doesn't exist. As an aside, I would also like to provide a set of views and the first one that exists is used, e.g.: @includefirstthatexists(['first-view', 'second-view', 'third-view'])

Elixir versioning public path

爷,独闯天下 提交于 2019-12-03 12:25:33
I'm trying to use Elixir's version() method with my 'public' folder being public_html (instead of the default 'public' method). I version my css file, which produces a build folder with the manifest inside public_html elixir.config.cssOutput = 'public_html/css'; elixir.config.jsOutput = 'public_html/js'; elixir(function(mix) { mix.styles([ 'vendor/normalize.css', 'app.css' ], null, 'public_html/css'); mix.version('public_html/css/all.css'); }); In my blade template I use <link href="{{ elixir("css/all.css") }}" rel="stylesheet"> Problem is the elixir function searches in 'public/build' folder.

laravel 5.2 How to get route parameter in blade?

筅森魡賤 提交于 2019-12-03 10:48:30
问题 this is my url http://project.dev/blogs/image-with-article so, here I need the parameter image-with-article in my blade to display which is a parameter named slug here is in my routes file I need the slug paramter in blade. Route::get('/blogs/{slug}', ['as'=>'blog.by.slug', 'uses'=> 'CmsController@show']); 回答1: I'm not sure what you mean. If you're trying to construct the route in a Blade template, use <a href="{{ route('blog.by.slug', ['slug' => 'someslug']) }}">...</a> If you're trying to

Go back URL in Laravel 5.1

我们两清 提交于 2019-12-03 08:06:07
问题 How can I get the previous URL visited on the website in Laravel 5.1? In Laravel 4 I just needed to write it like below: {{ URL::previous() }} 回答1: The cleanest way seems to be using the url() helper: {{ url()->previous() }} URL::previous() works for me in my Laravel 5.1 project. Here is Laravel 5.1 doc for previous() method, which is accessible through URL Facade . You can still try alternatives, in your views you can do: {{ redirect()->getUrlGenerator()->previous() }} or: {{ redirect()-

Can I use the Blade templating engine outside of Laravel?

妖精的绣舞 提交于 2019-12-03 06:52:04
i'm want to creating a design pattern and use the "Blade templating engine". Can I use the Blade templating engine outside of Laravel and use it in my new pattern ? magallanes For the record: I tested many libraries to run blade outside Laravel (that i don't use) and most are poor hacks of the original library that simply copied and pasted the code and removed some dependencies yet it retains a lot of dependencies of Laravel. So I created (for a project) an alternative for blade that its free (MIT license, i.e. close source/private code is OK) in a single file and without a single dependency

Laravel - Difference between @yield and @section?

大兔子大兔子 提交于 2019-12-03 06:28:55
问题 From the Laravel docs, you can include 'sections' inside layouts using two methods: <html> <body> @section('sidebar') This is the master sidebar. @show <div class="container"> @yield('content') </div> </body> </html> Since @yield can also pass in some default content using @yield('section', 'Default Content') , is @yield just a shorthand for a @section that do not uses @parent ? @section <!-- Nothing here --> @show What other differences are there? 回答1: This line clears out the confusion:

Blade view: if statement with OR/AND condition

谁说我不能喝 提交于 2019-12-03 05:59:59
Is it possible in Laravel 4.0 -blade-view to do an if statment like so? @if ($var1 === '1' OR $var2 === '1') //Do my stuff @endif Or @if ($var1 === '1' || $var2 === '1') //Do my stuff @endif Or whatever syntax it is. I didn't find anything in the L4 docs, does it exist ? It should support all of your standard PHP operators, including || (logical OR). I have tested it myself and it works fine. Additionally, I would recommend simply testing this yourself in future to confirm it works/doesn't work. You can simply use and / or operators: @if($a==1 and $b==2) @if($a==1 or $b==2) 来源: https:/