0

I have configured a back-end screen where I will enter a string as

{{price}} for guest user. click here {{sign_up}}.

So after I fetch the field value I want to dynamically replace the {{price}} variable to some custom price and {{sign_up}} to a cms page link.

Can anybody help me on how to do this? thanks

0

I have found a code to parse the variables using core php code.

public function findReplace($string, $find, $replace)
{
    if (preg_match("/[a-zA-Z\_]+/", $find)) {
        return (string) preg_replace("/\{\{(\s+)?($find)(\s+)?\}\}/", $replace, $string);
    } else {
        throw new \Exception("Find statement must match regex pattern: /[a-zA-Z]+/");
    }
}

this code can parse it and replace the values to what we want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.