Welcome Guest, Not a member yet? Register   Sign In
variable to layout
#2

You can set the variable from your controller, and then show the variable through a footer include:

app/Controllers/Cart.php
PHP Code:
<?php
namespace App\Controllers;
class 
Cart extends BaseController
{

    public function index()
    {
        $data['variable'] = "Footer variable";

        echo view('Cart/index'$data);
    }


app/Views/templates/layout_user.php
PHP Code:
<?= $this->renderSection('content'?>

<?= $this->include('\App\Views\templates\footer'?>

app/Views/cart/index.php
PHP Code:
<?= $this->extend('App\Views\templates\layout_user'?>
<?= $this
->section('content'); ?> 
<p>Some cart content here</p>
<?= $this->endSection(); ?>



app/Views/templates/footer.php
PHP Code:
<p><?= $variable?></p> 


Display:
Code:
<p>Some cart content here</p>
<p>Footer variable</p>
Reply


Messages In This Thread
variable to layout - by pippuccio76 - 01-18-2022, 01:17 PM
RE: variable to layout - by BilltheCat - 01-18-2022, 02:29 PM
RE: variable to layout - by pippuccio76 - 01-19-2022, 08:56 AM
RE: variable to layout - by BilltheCat - 01-19-2022, 09:10 AM
RE: variable to layout - by munaja - 07-10-2023, 11:16 PM
RE: variable to layout - by karthik_code - 12-24-2024, 02:20 AM
RE: variable to layout - by InsiteFX - 12-24-2024, 04:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB