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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:15:04+00:00 2026-06-07T11:15:04+00:00

Edit: Maybe I should make this part clear. A user is writing the template.

  • 0

Edit: Maybe I should make this part clear. A user is writing the template. So I want the syntax to be simple, and I can’t trust them with powerful template engines.

So, I need a template engine that will be used to write emails, using tokens (easy) with conditional logic (less easy).

Example: Hello{if first_name} dear {first_name}{endif}, blah blah blah.

If first_name is not available, it should read: Hello, blah blah blah.

I was able to get it working using eval… but we all know eval is evil.

$body = preg_replace('/{if ([^{\|}]+)}/i', '<?php if(isset(\$tokens[\'$1\'])):?>', $body);
$body = preg_replace('/{endif}/i', '<?php endif;?>', $body);

Can anyone point me towards a tutorial on this one? I can’t seem to find anything beyond simple token replacement.

  • 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-07T11:15:05+00:00Added an answer on June 7, 2026 at 11:15 am

    Using the comments from everyone, I was able to figure out how to quickly make my own secure template engine with custom syntax.

    Let’s say I want to make {first_name|buddy} be the first_name variable if it’s set, but if it’s not set use the string “buddy” as default.

    Use a powerful template engine, like Smarty. Smarty has support for this, but I don’t like the syntax {$first_name|default:"buddy"}

    Replace all occurrences of your custom syntax with the correct syntax

    preg_replace('/{([\w\s]+)\|([\w\s]+)}/', '{\$$1|default:"$2"}', $content);
    

    Then just run it through Smarty. This is essentially the same as using eval, but secure. Thanks guys.

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

Sidebar

Related Questions

EDIT : It turned out that this can only be done through an external
EDIT: Simple version of the question: I want to create server variables in the
Question is simple. How can I make 100% safe photo upload script with php?
Edit: Maybe I made the question more complex than it should. My questions is
jQuery(document).ready(function(){ // ok im geting the value here maybe i should make it in
Edit: I think this has been answered successfully, but I can't check 'til later.
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
Edit (updated question) I have a simple C program: // it is not important
How can I make it so when a tab is selected, the current one
I'm betting that someone has already solved this and maybe I'm using the wrong

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.