0

Is it good practice to inject HTML code using require_once (); in the middle of HTML?

Example:
<div id="col_left">
<?php require_once ('../application/top_sidebar.php'); ?>
</div>

2
  • sometimes it is sometimes it not, with out context who can say? Commented Sep 8, 2011 at 21:31
  • @Dagon Under what situations would this be a way that's preferred over putting the HTML in one page? Commented Sep 8, 2011 at 21:34

2 Answers 2

4

Is it good practice to inject HTML code using require_once (); in the middle of HTML?

Yes it is, after all that's why that function exists and including chunk of html that way is very common practice for example including header, sidebars, footer, etc to construct your templates.

That much php code is even permissible in MVC design pattern where you try to put minimum of php code inside the html.

Sign up to request clarification or add additional context in comments.

Comments

1

As this seems to be used in a page template, I think you can be sure not to call it more than once so you can use a simple require and save the _once check.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.