Using Templates with PHP

1

Save! I have a template system that I put up in PHP represented by the following structure:

require("header.php");
require("content.php");  //carregado dinamicamente via GET
require("footer");

Everything works fine, but I have to manage the CSS and JS of each content . Since CSS is inserted in header.php and JS in footer.php, what would be the best way to insert the specific files of each content ? The intent would be to load the scripts for the specific content , but I have problems mostly with JS when I try to insert them directly into content . Thanks in advance for the force!

    
asked by anonymous 01.08.2017 / 03:37

2 answers

1

You can use a variable!

//tens de declarar antes de chamar o arquivo content
$script = '<script type="text/javascript" src="source.js"></script>';

In the content.php

[..]
 echo (isset($script)) ? $script : '';
[..]

If you have multiple scripts you can use an array

    
01.08.2017 / 13:56
1

If you get via get the content parameter, try:

Assuming you are redirecting to a page called home . And you have created the files home.css , home.js , home.php

URL will be the parameter via get that you quoted.

NO HEADER

    <head>
      <link rel="stylesheet" type="text/css" href="<?php echo $_GET['url'];?>.css">
    </head>

NO CONTENT

<body> 
  require $_GET['url].'php';
</body>

NO FOOTER

<script type="text/javascript" src="<?php echo $_GET['url'];?>.js"></script>
    
01.08.2017 / 14:29