How to include blade tempate in another file? - laravel

I have two fiels:
landing.blade.php
And block comments.blade.php.
How can I include comments.blade.php inside landing.blade.php?

You can include one blade template into other by following syntax:
Including Sub-Views
#include('view.name')
You may also pass an array of data to the included view:
#include('view.name', array('some'=>'data'))
For more details you can follow:
https://laravel.com/docs/5.0/templates
Thanks

According to the documentation you need to #include it:
landing.blade.php:
<div>
Some content
#include('comments', ['comments' => $comments])
</div>

simple way,
if landing.blade.php and comments.blade.php are on the same directory, let's assume they are both on ressource/view
So on landing.blade.php you can write #include('comments')

Related

Difference between #aware and #props directives in laravel 9

The #aware Laravel Blade template directive was introduced in Laravel 8, but I still don't understand what it does differently from the already existing #props directive.
For instance, if I use a Blade template like this:
<x-view-content :page="$page ?? ''" />
and the component used above is defined in views/components/view-content.blade.php like this:
#aware(['page'])
<div>
{{ $page }}
</div>
I get the page successfully rendered inside the component. However, replacing #aware(['page']) with #props(['page']) produces the same result.
I would like to know what the differences between them are.
#aware is for accessing data from a parent component where you have #props. You can find here all relevant information. In your case you don't have child component.

How to render multiple livewire component as string?

I have multiple livewire components e.g. opd.patient-count, opd.visit-count, opd.checkup-count and so on. I would like to store these components name into database then call by user role. Anyway, It does not work once I tried as below.
foreach ...
echo '<livewire:opd.patient-count />';
endforeach ...
Any advice or guidance on this would be greatly appreciated, Thanks.
As I understand your problem, You can achieve using this syntax instead
#foreach($components as $eachComponent)
#livewire($eachComponent,['componentData' => $data])
#endforeach
in this code above, the component name is assigned accordingly using a blade #foreach directive and iterate over each element and make the component.

Laravel include a template with dynamic value

I want to include a template dynamically eg: #include('{{ site('theme') }}.header')
but this throws up an error, how can I do this? (If I output {{ site('theme') }} this holds a value of test).
Thanks in advance.
Just write it like php code.
#include(site('theme').'.header')
Use this:
#include(site('theme') . '.header')

How to use include function in another custom function?

I am using Smarty 3.1.8
I want to include a tpl file only one time on page even if tpl file called more times.I dont know that I can do the that with Smarty without write a new custom function.So I think to write a new custom include function for this.
Can I use include function of smarty in the custom include function ?
I want to use smarty include function in my the custom include function for compile given template.
How am I do this ?
I want to use as follow :
{include_js file="script.users.tpl"}
Are you using PHP? If, so try this:
Even though it's in Smarty, use the php include_once("/dir/filename"); function.
using smarty_bc or smarty2:
{some_smarty.tpl}
<html>
<p>ex paragraph one</p>
<p>ex paragraph two</p>
{php} include_once("script.users.tpl"); {/php}
</html>
This way you can rely on having PHP monitor that the file is only being inserted once.

adding attributes to form_open_multipart

I was wondering how could we add attributes to file_upload in codeigniter
right now I am using form_open_multipart('controller');
but I want to add an id attribute to it.
Any help appreciated thanks!
From the User Guide:
form_open_multipart()
This function is absolutely identical
to the form_open() tag above except
that it adds a multipart attribute,
which is necessary if you would like
to use the form to upload files with.
So, you would use it in the same way you use form_open(). Example:
form_open_multipart('controller', 'id="my_id"');
Or:
form_open_multipart('controller', array('id' => 'my_id'));

Resources