Welcome Guest, Not a member yet? Register   Sign In
Way to include partial file on layout file
#3

(01-29-2022, 06:49 PM)iRedds Wrote: <?= $this->include('path/relative/to/the/Views/directory') ?>

In my original post, how am I not relative to the Views directory?


Code:
Views
|>layout
  >partials
   -head.php
  -master.php

From Views the file master.php is in layout, partials is a sub-directory of layout and head.php is in partials.


Before my original post, I tried variations such as


<?php $this->include('../partials/head.php'); ?> <-- partials back in Views
<?php $this->include('./partials/head.php'); ?> <-- same as without './'

I have also tried with and without '.php'

Why would CI see head.php as an invalid file?

If I do `<?php include('./partials/head');` The error generated is `include(partials/header): failed to open stream: No such file or directory` which makes sense.  PHP include requires '.php'.  If I modify it to `<?php include('./partials/head.php');`, the result works as expected and the include is pulled into the resulting syntax.
Reply


Messages In This Thread
RE: Way to include partial file on layout file - by dwlamb - 01-29-2022, 08:52 PM



Theme © iAndrew 2016 - Forum software by © MyBB