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 6334437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:39:30+00:00 2026-05-24T18:39:30+00:00

I use a MVC PHP framework to keep my web applications as DRY as

  • 0

I use a MVC PHP framework to keep my web applications as DRY as possible. All of my HTML templates are neatly tucked away in one folder in the application scope of my project.

The problem is that whenever I use a JSON string to build a page with AJAX, I need to reuse a lot of lines from these templates and copy them somewhere in my JavaScript files. This means there is code duplication between templates in my JavaScript files and templates in my PHP application.

I was wondering how this duplication can be prevented. One way is of course to load the template using AJAX, but then I would end up with a double AJAX request for one page. Furthermore, the PHP templates uses different tag styles to represent variables than MooTools, but the HTML setup is the same.

So to summarize: is there any neat way or a tool to prevent duplication of templates so one file could be used in both PHP and JavaScript? For the record: I use the MooTools framework to build my JavaScript files.

Edit

After some research, I found the best answer yet in my opinion. For those who are interested:

  • PURE

PURE separates HTML representation and JavaScript logic completely so you don’t have to bother including HTML elements in your scripts. The template can simply be provided in the HTML file itself.

Example:

// JSON string
{ 'who': 'me' }

// In your rendered HTML page:
<div id="who"></div>

// After the JSON string is sent back
<div id="who">me</div>

Furthermore, it can be used by a wide selection of libraries: MooTools, jQuery, dojo, Prototype etc.

  • 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-05-24T18:39:30+00:00Added an answer on May 24, 2026 at 6:39 pm

    Interesting question that I’m struggling with sometimes too.

    • you can put your html in your javascript code, which is duplicating and which you want to avoid

    • you can load your html with a separate ajax call, which causes more ajax calls to be run, and possible slowing down of your app. you may want to avoid it.

    • you can pass your html within the Ajax call that will load the data. That way, you only have one call. Let your PHP open your templates, and add them to the data-json stream.

    • you can put the template inside your original html, put it as hidden.

    I’d go for solution 3, or possibly 4 if templates are small and limited.

    The JSon would then be something like {“data”: … your original data object, “templates”:{…}}

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

Sidebar

Related Questions

I'm creating a PHP web application framework (MVC). I'd rather not use external libraries
For class, I would like a to use PHP MVC framework very similar to
I'm working on a PHP web app and I'm trying to use the MVC
I am writing a web application using PHP. I want to use the MVC
Whether you structure your PHP application yourself or use a framework (MVC or other),
I use the Symfony PHP MVC framework. I'm using JSON to pass an AJAX
Thank you one and all. I have an PHP MVC framework that uses XSLT
I use PHP with CodeIgniter(MVC framework). My Question is fairly simple. What according to
I want to write a basic MVC framework and blog in PHP, and use
I'm a PHP developer, and I use the MVC pattern and object-oriented code. I

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.