How to prevent html and PHP mixing up
-
The html designer is giving me html templates and i should add php code to it. Both PHP and html are mixing up and becoming very ugly. Hard to maintain or make changes in the future. How to format properly? I know Template engines, but i think it adds additional complexity.
-
The html designer is giving me html templates and i should add php code to it. Both PHP and html are mixing up and becoming very ugly. Hard to maintain or make changes in the future. How to format properly? I know Template engines, but i think it adds additional complexity.
By definition PHP and HTML should be mixed - that's the way PHP works. However the level of the mixing is up to you (or your template), you are the one who have to define what code is necessary to be in the HTML and what can be sit in pure PHP modules and called by the proper code from the HTML. It's not clear from your question what HTML designer messing with your code, but in any case you can go for total control using some pure text editor :) ...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
-
The html designer is giving me html templates and i should add php code to it. Both PHP and html are mixing up and becoming very ugly. Hard to maintain or make changes in the future. How to format properly? I know Template engines, but i think it adds additional complexity.
This is to expand upon the previously given answer. Yes, HTML and PHP are mixed but there are methods you can follow to split design from content which is usually the way to go whether you are doing all of the site development and then maintaining it yourself or if you're developing the site to be handed over to content people. Here is a VERY simple/rough sample of how I try to achieve this myself:
<html>
<head>
<title>My Title</title></body>
</html>Note: I had to remove the closing PHP tags in the example because it was messing up the rest of the entire post. Now this is the PHP page which you would give to whomever handles the content of each page. They can just keep making copies of the file and name them how they wish to create the multiple pages that make up the site. Now you have: MODULES.php
';
}
?>In some of my sites I have membership service. If the visitor is not logged into the site, the user_menu function will print out the HTML to create the login form. If they have an account and are logged in then the user_menu function will print a table of links involving their account. All of the checking whether or not someone is logged in is handled in the function located in modules.php. Now, you could do this as many times as is necessary throughout your php files. Just tell the content manager to not touch anything around/within the PHP tags. This will GREATLY minimize the amount of code that you want the PHP interpretor to process being shown within each physical PHP file that someone else will be working with. This is something of a cheap templating system. If you have PHP modules that do not print anything out to the browser then it isn't as important where you place the function calls amongst the HTML tags. But this will give you more solid control over placement of HTML elements/objects that are created by your PHP. I believe that it is
-
The html designer is giving me html templates and i should add php code to it. Both PHP and html are mixing up and becoming very ugly. Hard to maintain or make changes in the future. How to format properly? I know Template engines, but i think it adds additional complexity.
Hi, You have to move on to the next level, a framework. I can recommend you take a look at CodeIgniter framework or Smarty. Simple, fast and robust for small and medium complexity apps. For enterprise I would go with Zend framework.