Welcome Guest, Not a member yet? Register   Sign In
Views/Rendering Variable Issues?

(This post was last modified: 10-11-2016, 11:22 AM by enlivenapp.)

I have a project that will be built on CI4 and I have some time to play around with it today for giggles.

I'm loosely following the Static Pages Tut and have noticed there's issues (for me) passing variables through view calls.  I have a pretty good idea why this is happening and wondering if there's a workaround other than passing each expected variable through the view call.  so....

I have a directory that looks like this:
- Views
 - Templates
     - Layouts
        - default.php
     - Partials
        - Default
            - meta.php
            - header.php
            - footer.php
        - etc...

in my controller, I do the usual stuff, nothing special, of calling views...
public function index()
        $data['title'] = "Test Page";

        echo view('templates/layouts/default', $data);

All goes well so far, here's where it get's a bit troublesome.

In Templates/Layouts/Default/default.php
<!doctype html>
<!-- call meta partial -->
    <?php echo view('templates/partials/default/meta') ?> // throws missing variable error

       <?php echo view('templates/partials/default/meta', ['title' => $title]) ?>  // usable variable in partial view

       <h1><?= $title; ?></h1>

in Templates/Partials/Default/meta.php
       <title><?= $title; ?></title>

One would expect the $title variable to be available as it's being called from the layout file, which has access to the $data['title'] variable but CI throws an error about the missing variable $title.

I'm still getting read up on the docs, and there's not much currently available about templates/rendering/etc, so I'm relying on CI2/3 conventions for this experiment.  I have read a bit about view cells, should I be using that or is CI4 just not quite up to speed on the views/rendering/etc stuff?

Just to make sure I'm being fairly clear about it all, I was expecting access to all the $data passed from the controller to the view in all the Layout and Partial views.

Messages In This Thread
Views/Rendering Variable Issues? - by enlivenapp - 10-11-2016, 11:18 AM
RE: Views/Rendering Variable Issues? - by sv3tli0 - 10-11-2016, 11:09 PM

Theme © iAndrew 2016 - Forum software by © MyBB