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

  • Home
  • SEARCH
  • 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 518611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:57:17+00:00 2026-05-13T07:57:17+00:00

I am wondering the best way to store html templates in a database where

  • 0

I am wondering the best way to store html templates in a database where I am able to retrieve them and insert variables.

Obviously I could store them as php and then ‘EVAL’ the record…. but I heard it was evil.

is there a better way? 🙂

edit:

Sorry I wasn’t clear… I tried to simplify it by saying html templates… what I really meant was small embed-able html elements (think youtube)… rather than an entire site.

  • 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-13T07:57:17+00:00Added an answer on May 13, 2026 at 7:57 am

    I would also advice against storing the HTML inside the database. It’s much more convenient to store them as templates on the file-system and include them or parse them when needed. I also recommend using something like Smarty. A very handy tool, that is.

    However, if you would rather do it manually, here is what I would do.

    First, I would store the template in a file on the file-system. If you would rather use a database, that can be done to. Just know that a database will, usually, cause more overhead when used for stuff like this.

    For example, in the case of a YouTube video:

    <object width="{$width}" height="{$height}">
        <param name="movie" value="http://www.youtube.com/{$path}"></param>
        <param name="allowFullScreen" value="true"></param>
        <param name="allowscriptaccess" value="always"></param>
        <embed src="http://www.youtube.com/{$path}"
               type="application/x-shockwave-flash"
               allowscriptaccess="always"
               allowfullscreen="true"
               width="{$width}" height="{$width}">
        </embed>
    </object>
    

    Then I would simply str_replace the PHP variables in there, much like PHP itself does with strings.

    <?php
    $template_path = 'templates/youtube_vid.tpl';
    $template_data = file_get_contents($template_path);
    
    $old = array('{$width}', '{$height}', '{$path}');
    $new = array(425, 344, 'v/zuZB2O6orV0&hl=en_US&fs=1&');
    
    echo str_replace($old, $new, $template_data);
    ?>
    

    And that would be it.

    You could of course use <?php $width; ?>-like placeholders and just include the template, but that leaves you at risk for injection attacks. This is the safer route.

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

Sidebar

Related Questions

I'm wondering what's the best way to save precompiled handlebar templates and include them
I'm wondering what the best way is to store user settings? For a web
I'm wondering what would be the best way to store math constants that are
I've been wondering what the best way to store data would be in my
I was wondering what is the best way to store usernames and password to
What is the best way to store instances of a class to file/database? We
Just wondering what the best way to store user login data on successful login
i was wondering what the best way to store a file name in a
I'm wondering what the best way is to store the positions of objects in
I was wondering what is the best way to store static content for my

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.