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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:18:57+00:00 2026-06-14T00:18:57+00:00

I am creating an OpenCart extension where the admin can change his email templates

  • 0

I am creating an OpenCart extension where the admin can change his email templates using the user interface in the admin panel.

I would like the user to have the option to add variables to his custom email templates. For example he could put in:

Hello $order['customer_firstname'], your order has been processed.

At this point $order would be undefined, the user is simply telling defining the message that is to be sent. This would be stored to the database and called when the email is to be sent.

The problem is, how do I get “$order['customer_firstname']” to become a litteral string, and then be converted to a variable when necessary?

Thanks
Peter

  • 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-14T00:18:58+00:00Added an answer on June 14, 2026 at 12:18 am

    You could define your own simple template engine:

    function template($text, $context) {
        $tags = preg_match_all('~%([a-zA-Z0-9]+)\.([a-zA-Z0-9]+)%~', $text, $matches);
    
        for($i = 0; $i < count($matches[0]); $i++) {
            $subject = $matches[0][$i];
            $ctx = $matches[1][$i];
            $key = $matches[3][$i];
            $value = $context[$ctx][$key];
    
            $text = str_replace($subject, $value, $text);
        }
    
        return $text;
    }
    

    This allows you to transform a string like this:

    $text = 'Hello %order.name%. You have %order.percent%% discount. Pay a total ammount of %payment.ammount% using %payment.type%.';
    
    $templated = template($text, array(
        'order' => array(
            'name' => 'Alex',
            'percent' => 20
        ),
    
        'payment' => array(
            'type' => 'VISA',
            'ammount' => '$299.9'
        )
    ));
    echo $templated;
    

    Into this:

    Hello Alex. You have 20% discount. Pay a total ammount of $299.9 using VISA.
    

    This allows you to have any number of variables defined.

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

Sidebar

Related Questions

Creating MVC3 Razor Helper like Helper.BeginForm() says that it can be done using extension
Creating a browser based single-page browser based RIA. Would like to make use of
Creating a web interface so our helpdesk can create users and setup some of
I am creating an e-commerce website using OpenCart and hostgator for hosting. I want
creating a small web application to be deployed on Heroku, where we would like
I am using opencart for an online shop I am creating. When I look
Creating a google map with store locations within 50 miles of user entered address.
Creating a simple RPG game, first time using XNA. Trying to get my character
I creating a web application using JSF,Hibernate,Spring. I have added a filter for checking
Creating a site in with FrogCMS and using alot of jquery to create an

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.