Jump to content

Recommended Posts

I've always found the task difficult. I use includes and functions wherever I can, but sometimes it seems impossible. Take this code for example:

 

<div>
<?php
	$gotContents = printContents($linkDB, 'home');
	foreach($gotContents as $k){
		echo "<div class = \"catContents\">";
			echo "<div class = \"contentTitle\">".contentTitle($linkDB, $k)[0]."</div>";
			echo cutContent($k);
		echo "</div>";
	}
?>
</div>

Here, there's no way (that I can see) to separate the HTML from the PHP; I can't divide the code into different files since I need parts of it to be encased in DIVs. So, is this type of code acceptable, or is there a better way to handle it? If so, how?

 

Thanks in advance for any replies.

 

EDIT: Also, I'm not interested in using any third-party software/add-on- just raw PHP and HTML please.

Edited by BorysSokolov
Link to comment
https://forums.phpfreaks.com/topic/275299-cleanest-way-to-separate-php-and-html/
Share on other sites

I like to use a templating system like Smarty, but for some reason you don't want to... So...

You could use a HEREDOC to use one echo statement, and get the returned value of cutContent() before the echo's.

 

I've just done some research, and changed my mind. I guess using a template engine really would be the best solution. So, this leads me to another question: which template should I use, as a beginner? Smarty seems to be the standard, I gather?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.