Welcome Guest, Not a member yet? Register   Sign In
How to create templates
#4

Which version of CodeIgniter are you using?

If it's the latest CI4 - templating is very easy. Take a look at this - https://codeigniter4.github.io/userguide...youts.html

Step 1 - create your template file - Views/app.php

PHP Code:
<!doctype html>
<
html>
<
head>
   <title>My Layout</title>
</
head>
<
body>
   <?= $this->renderSection('content'?>
</body>
</html> 

Step 2 - create any page e.g. home page Views/homepage.php
PHP Code:
<?= $this->extend('app'?> //This is the name of layout file above without ".php" 

<?= $this->section('content'?>
    <h1>Hello World! Welcome to my website.</h1>
<?= $this->endSection() ?>

Step 3 - In your controller
PHP Code:
public function index()
{
 
   echo view('homepage');


Depending upon your are requirements - you can create different types of layouts e.g. publicLayout.php or adminLayout.php

You can also include partials too - check out all options here - https://codeigniter4.github.io/userguide/outgoing
Reply


Messages In This Thread
How to create templates - by mitsol - 04-17-2019, 08:10 AM
RE: How to create templates - by php_rocs - 04-17-2019, 03:35 PM
RE: How to create templates - by website - 04-18-2019, 04:53 AM
RE: How to create templates - by happyape - 04-18-2019, 05:29 AM
RE: How to create templates - by soap - 04-19-2019, 01:19 AM
RE: How to create templates - by HelenM - 04-19-2019, 03:03 AM
RE: How to create templates - by vincent78 - 04-20-2019, 03:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB