I have some code in database
<div class="container py-1">
#include('layouts.tester')
</div>
When I show data from database i show
"#include('layouts.tester')"
I want to include my file than show text.
how can I do it to make it work?
#include means include files include a blade file. So for this you va to #extends('layouts.app') then where you want to show the file just use yield like below
#yield('content')
Then in which page you want to replace just use it like this
#section('content')
//your buttons/forms goes here
#endsection
I was hoping someone could help me with my understanding when using the #sectoin and #yield commands inside a themosis 1.2 scout template.
Basically I have a view "/views/my-page.scout.php" with some basic html markup:
#include('includes.header')
<div> some content </div>
#yield('extra-content')
#include('includes.footer')
enter code here
Then inside of another file located in "views/extras/extra-content.scout.php" I have the following:
#section('extra-content')
<div>Some extra content</div>
#stop
Im not sure why my #yield is not working, I know I could just use #include but I wanted to get a better understanding of using #yield. Ive checked out the laravel and themosis documentation but im still confused.
Any help would be most appreciated. :)
File location: /views/extras/extra-content.scout.php
File name: extra-content.scout.php
File Contents:
#section('extra-content')
<div>Some extra content</div>
#stop
File location: /views/my-page.scout.php
File name: my-page.scout.php
File Contents:
#include('includes.header')
<div> some content </div>
#yield('extra-content')
#include('includes.footer')
File : my-page.scout.php
#include('includes.header')
#include('extras.extra-content')
<div> some content </div>
#yield('extra-content')
{{-- or include here #include('extras.extra-content') --}}
{{-- or include here #include('extras.extra-content') --}}
#include('includes.footer')
the file extra-content should be included explicitily in this file or any file it's extending/including.
yield will just store the content in a variable with will be available in this file.
In your use case, including may be the best way, because your file contains only that section. imagine a extra-content file where you will output some content and handle 'extra-content` variable
section content will always be placed where you yield it.
this code
#section('my-content')
i want to place to place this content somewhere
#stop
will be interpreted as:
$sections['my-content'] = 'i want to place to place this content somewhere';
and
yield('my-content');
is intepreted as
echo isset($sections['my-content']) ? $section['my-content']:'';
Edit imagine your file extra-content where you define the section doesn't contains only the section definition:
File: extra-content
#section('my-content')
this is yielded content displayed where you use yield('my-content')
#stop
<p> this will be displayed where the file is included</p>
I have the site with the structure like:
First: master.blade.php : this contain section('content')
<body>
#include('partial.header')
#yield('content')
#include('partial.footer')
</body>
Second index.blade.php : contain section('content').
#extends('layouts.master')
#section('content')
<div id="container">
<div id="news">
#yield('news')
</div>
<div id="apartment">
#yield('apartment')
</div>
</div> <!-- ./container -->
#endsection
Third: news.blade.php : this simple to show all news
#foreach($posts as $post)
#endforeach
Final file: apartment.blade.php : this simple to show all apartment.
#foreach($apartments as $apartment)
#endforeach
My route direct to master.blade.php.
My question is:
When I include news with #yield('news') in index.blade.php. It shows correct all news in my database.
But when I delete #yield('news') in index.blade.php. It also show news from my database (but it's lost css/js for that).
Why I deleted #yield('news'), it's should don't show any news on my page?
Seem Laravel Blade not support two #yield in #section. When I add only 1 row #yield('news') into index.blade.php file. It shows list news on my index page. When I continues add #yield('apartment'). Don't have any apartment shown on the index page. I certainly it has values when foreach to get data. I also test with HTML statics but don't have anything changes.
My route direct to master.blade.php.
Index extends master, so point your route to index view.
If sections continue to be yielded, after #yield removal, I think the framework is loading a cached view.
Try clearing the view cache php artisan view:clear or use php artisan --help view:clear for help.
Also #yield yields a section in a parent child relationship.
Change yields to include like #include('partial.news') if news are in partial folder or to whatever the path. Rendering could be manipulated using #isset or #empty statements or even #forelse loops.
Blade Control Structures.
I have a sample view:
File: hello.blade.php
//includes the basic html enclosed tags
<p>Hello world<p>
#yield('content')
File: tester.blade.php
#extends('hello')
#section('content')
<p>this is a test<p>
#yield('contents')
#endsection
File: content.blade.php
#extends('tester.blade.php')
#section('contents')
<p>any code will do<p>
#endsection
now my problem is whenever it only renders
Hello world
this is a test
is there any workaround this? or blade engine does not support nested yields? anyhelp will be greatly appreciated
I have not tested but you could try change content.blade.php to
#extends('tester')
and make sure you use
return view('content');
However #include inside #section works. or using #parent in content.blade.php
#extends('tester')
#section('content')
#parent
<p>any code will do</p>
#endsection
#parent will cause Blade to append parent view content with current view rather than overwrite whole section.
I've tested it but doesn't do what we expect.
But there is one solution that I still use when I'm facing to such situation. I use #parent blade directive like this
File: hello.blade.php
{{-- includes the basic html enclosed tags --}}
<p>Hello world<p>
#yield('content')
File: tester.blade.php
#extends('hello')
#section('content')
<p>this is a test<p>
#yield('contents')
#endsection
File: content.blade.php
#extends('tester.blade.php')
#section('contents')
#parent
<p>any code will do<p>
#endsection
I'm rendering a page that is primarily a form with view::make in Laravel and it is crashing, causing ERR_CONNECTION_RESET. After a long investigation and many red herrings, I started erasing (not commenting) random sections out of the blade file for the view and realized that if I
a) erase 2 of the {{Form}} calls inside this section of the form
b) remove the {{-- and --}} from around this section of the form
{{--
<div class="form-row">
{{ Form::label('foo', 'foo:') }}
{{ Form::text('foo') }}
</div>
<div class="form-row">
{{ Form::label('foo', 'foo:') }}
{{ Form::text('foo') }}
</div>
<div class="form-row">
{{ Form::label('foo', 'foo') }}
{{ Form::text('foo') }}
</div>
--}}
the page will render. I am not sure what exactly the cause here is. There are other blocks above and below, although this is a 3-div commented out section which none of the others are.
Anyone have a clue what is causing this? Running on WAMP if that matters.
Blade comments should only be used for simple remarks or to comment out single-line Blade functions. A single Blade comment cannot be used to comment out multiple lines of code.
Use PHP Block Comments instead. They are still usable in a blade.php file
<?php /*
{{ HTML::form("foo") }};
{{ HTML::form("bar") }};
*/ ?>
Alternatively, comment out your Blade one line at a time:
{{-- HTML::form("foo") --}};
{{-- HTML::form("bar") --}};
Examples of Valid Blade Comments:
Single Blade Function:
{{-- Form::text('foo') --}}
Remark:
{{-- Form Section 1 --}}
Examples of Invalid Blade Comments:
Incorrect syntax:
{{-- Form::text('foo') -- }}
"#" Inside of Blade comment
{{-- #Form::text('foo') --}}
Nested PHP:
{{-- <?php
echo "foo";
echo "bar
?> --}}
Nested Blade:
{{--
{{ HTML::form("foo") }};
{{ HTML::form("bar") }};
--}}
Internals:
Using the sample code from the question, Laravel's Blade Compiler will generate a temporary PHP file containing the following PHP and HTML:
<?php /*
<div class="form-row">
<?php echo Form::label('foo', 'foo:'); ?>
<?php echo Form::text('foo'); ?>
</div>
<div class="form-row">
<?php echo Form::label('foo', 'foo:'); ?>
<?php echo Form::text('foo'); ?>
</div>
<div class="form-row">
<?php echo Form::label('foo', 'foo'); ?>
<?php echo Form::text('foo'); ?>
</div>
*/ ?>
The Blade code inside of the Blade comments are still parsed into PHP. The PHP end tags inside of the PHP block-comment can cause compilation issues:
?> breaks out of PHP mode and returns to HTML mode, and // or #
cannot influence that.
Comments in Blade are very simple!
{{-- Blade comments that wil not appear in the rendered HTML output --}}
You can either do normal PHP comments:
<? /* some comment here */
// or single line comments
# or these :)
?>
I have same problem with laravel 5.1 and PHP 7 (new homestead). The work around was to use this:
<?php /* XXX */?>
instead of this:
{{-- XXX -- }}.
I have a similar symptom and it seems to be related to the length of the comment alone. I tested it with a comment that doesn't contain any PHP code or blade statements at all:
{{--
0123456789abcdef
0123456789abcdef
0123456789abcdef
--}}
I kept adding copies of the repeated line until it crashed. The comment was lexically followed by a blade #if statement, and the corresponding <php if(...): ?> did not end up in the compiled template, but the closing <?php endif; ?> did, resulting in a syntactically invalid compiled template.
It seems to be a bug in the blade compiler and I will report it.
The workaround is to split long blade comments with --}}{{--.
I have Tried the
Nested PHP:
{{-- <?php
echo "foo";
echo "bar";
?> --}}
#TonyArra
While using . It is Not Commenting the Content and prevents from Compiling as HTML
and this is the htmlsource
{{-- foobar --}}
Which i have got
Thats Because If You want To Comment the php Code inside Blade
Try this
<!-- #php echo 'hai'; #endphp -->
OR
<!-- <?php echo 'hai'; ?> -->
and try to view the page source
Blade comments like this one, were the problem in my case:
{{--
#if ($test)
<div>something</div>
#else
<div>something else</div>
#endif
--}}
Simply we have to use a double curly bracket followed by a double hyphen.
This will work for the single line as well multiple lines.
{{-- --}}
Blade Comments
{{-- This comment will not be present in the rendered HTML --}}
Referene: https://laravel-news.com/laravel-blade-comments