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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:55:20+00:00 2026-05-22T21:55:20+00:00

I’m searching for a very basic PHP templating system. Right now I’m using: /**

  • 0

I’m searching for a very basic PHP templating system. Right now I’m using:

/**
 * Renders a single line. Looks for {{ var }}
 *
 * @param string $string
 * @param array $parameters
 *
 * @return string
 */
function renderString($string, array $parameters)
{
    $replacer = function ($match) use ($parameters)
    {
        return isset($parameters[$match[1]]) ? $parameters[$match[1]] : $match[0];
    };

    return preg_replace_callback('/{{\s*(.+?)\s*}}/', $replacer, $string);
}

(from here: PHP – Extremely light templating system)

but I can only assign and display variables. I also need a way to use conditions like IF and loop arrays.

I found Rain TPL – http://www.raintpl.com/Quick-Start/#if – which is very close to what I’m looking for, but there are a few things that I don’t like it it:

  • it allows the dude who is writing the template to run PHP functions (inside the IF condition).
  • it writes cache and php files, which I don’t want

So, is there anything out there similar to this, but even more “basic”, strict, and more secure?

  • 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-22T21:55:21+00:00Added an answer on May 22, 2026 at 9:55 pm

    From your requirements I am guessing you are wanting your website users to write some basic php scripts. You might not find a free template engine that does that.

    I think it’s better for you if you change an existing template engine to your needs.

    You can change Rain TPL to disable some of its features that you don’t want. For example you can do…

    1. Disable function use in IF statements:
      a. Locate elseif( preg_match( '/\{if(?: condition){0,1}="([^"]*)"\}/', $html, $code ) ){

      b. Replace $this->function_check( $tag ); with a new method something like $this->ifcondition_function_check( $tag );

      c. Create the new method that will disable all functions in IF statements.

      private function ifcondition_function_check($code)
      {
          $preg = '/[a-zA-z0-9]+\((.*?)\)/';
          if (preg_match( $preg, $code, $match ) ){
              // find the line of the error
              $line = 0;
              $rows=explode("\n",$this->tpl['source']);
              while( !strpos($rows[$line],$code) )
                      $line++;
      
              // draw the error line
              $error = str_replace( array('<','>'), array( '&lt;','&gt;' ), array($code,$rows[$line]) );
              $error = str_replace( $code, "<font color=red>$code</font>", $rows[$line] );
      
              // debug the error and stop the execution of the script
              die( "<div>RainTPL Sandbox Error in template <b>{$this->tpl['tpl_filename']}</b> at line $line : <i>$error</i></b>" );
          }
      }
      

      d. Now functions are disabled.

      1. Remove the cache file. (The cache file in Rain TPL is a PHP file with the template tags replaced by PHP code)
        a. Go to method draw()
        b. Locate unset( $this->tpl );
        c. Just before this line remove the complied (cache) file @unlink($this->tpl['compiled_filename']);.
        d. Now the cache file is just a temporary file to execute the PHP code.

    Hope this helps

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.