John Davidson

php - Reusing Blade Template in different tabs

0 comments
Message:


I have body.blade.php in table folder that displays an array passed from controller to view


@include('table.body', [$cols, $rows, $table_no])

Now, I have converted that array into percentage and would like to show that too. I passed the $table_no and $table_percentage. In the view I have coded


Tab 1 - View Numbers

@include('table.body', [$cols, $rows, $table_no])

Tab 2 - View Percentage

@include('table.body', [$cols, $rows, $table_percentage])

I have duplicated the body.blade.php for $table_no and $table_percentage but wish to know if there is an elegant way to do this.



My Answer:
One way to achieve this is by using conditional statements in the body.blade.php file to determine which data to display based on the variable passed from the controller.

For example, you can modify the body.blade.php file to include a conditional statement like this:

@if(isset($table_percentage))
// Display percentage data
@else
// Display regular data
@endif

This way, you can reuse the same blade template file for both tabs by passing the appropriate data from the controller. This approach helps in keeping the code DRY (Don't Repeat Yourself) and avoids duplicating the template file for each tab.

Rate this post

3 of 5 based on 8578 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us