• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to disassemble html skills?

#1
There are dozens of php html structures as follows...


<body>
<section></section>
<nav></nav>
<section></section>
...

</body>

Where <nav></nav> is the shared part.
The menu content in nav also uses the php template syntax <?php xxxx ?>
I put the content into nav.php and put it in view/common/nav.php

Consult  https://codeigniter4.github.io/userguide...index.html
I hope to insert the code from here.

<body>
<section></section>
Insert code to come in here
<section></section>
...

</body>
, and keep html integrity,

What should be done best?
Reply

#2
One possibility is to use the View Parser (https://codeigniter4.github.io/userguide...arser.html)

Build your view as
Code:
<body>
<section></section>
{codeGoesHere}
<section></section>
...
Build your code to go in the middle, and assign it to something, eg $whateverYouSavedYourRealBodyAs,
and then render the view with the nested content:

Code:
$parser = \Config\Services::parser();
$parser->setData(['codeGoesHere' => $whateverYouSavedYourRealBodyAs])
             ->render('theTemplateWithTheFragmentShownAbove');

This technique is used in the CodeIgniter website (CI4 version being published very soon).
Reply

#3
(08-29-2019, 09:19 PM)ciadmin Wrote: One possibility is to use the View Parser (https://codeigniter4.github.io/userguide...arser.html)

Build your view as
Code:
<body>
<section></section>
{codeGoesHere}
<section></section>
...
Build your code to go in the middle, and assign it to something, eg $whateverYouSavedYourRealBodyAs,
and then render the view with the nested content:

Code:
$parser = \Config\Services::parser();
$parser->setData(['codeGoesHere' => $whateverYouSavedYourRealBodyAs])
             ->render('theTemplateWithTheFragmentShownAbove');

This technique is used in the CodeIgniter website (CI4 version being published very soon).

So great!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.