Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7725901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:04:13+00:00 2026-06-01T05:04:13+00:00

I have a chunk of HTML code (with some PHP vars echoed inside of

  • 0

I have a chunk of HTML code (with some PHP vars echoed inside of it) that I need show on multiple times (inside a loop) AND on multiple pages.

So how to keep it DRY?

My ideas admittedly were not brilliant:

  • Putting it in a separate file and including – but then I’ll do an include inside a loop and it showed like bad practice.

  • Putting it in a function – but then I have to make variables global plus it just doesn’t look to me like functions are meant for such usage.

Is there a better way? Is this where maybe OOP has a solution? (I run php 5.3)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:04:15+00:00Added an answer on June 1, 2026 at 5:04 am

    Use templates.

    Just write your loop inside of the template, as well as all other presentation code.

    <h1>Some list</h1>
    <ul>
    <?php foreach($data as $row): ?>
      <li><?=$row['name']?> whatever your block code goes here</li>
    <?php endforeach ?>
    </ul>
    

    so, no need to include anything at all.

    For the multiple pages you may wish to make a helper function, called from the template.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have some code like this: <html> <head><title>Title</title></head> <body> <?php if (!$someCondition){
I have a script that attaches actions to some objects in my HTML code.
I have a big chunk of HTML which is a template for some data
I have a chunk of code where it appears that a variable is changing
Okay, so I have an javascript function that retrieves some HTML... function updateQuestions(i){ var
I have a chunk of html code stored in a field in a mysql
I have the following chunk of HTML code but i cant figure how i
In one of my Django templates, I have a chunk of HTML which repeats
I have this string containing a large chunk of html and am trying to
I have a chunk of javascript that users can copy and paste to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.