Javascript: functiontemplete (str, data) {returnstr. replace ({%) + ([^ ({%)] w *) (%}) + ig, function (all, left, key) {if (data [key]) {returndata [key];} else {return ;}});} templete (your tribe name: {% name % }, application modified to: {% oname %}. cause of failure:
Javascript: function templete (str, data) {return str. replace (/({%) + ([^ ({%)] \ w *) (%}) +/ig, function (all, left, key) {if (data [key]) {return data [key];} else {return '';}});} templete ('your tribe name: {% name %}, application modified to: {% oname %}, cause of failure:
Javascript:
Function templete (str, data) {return str. replace (/({%) + ([^ ({%)] \ w *) (%}) +/ig, function (all, left, key) {if (data [key]) {return data [key];} else {return '';}});} templete ('your tribe name: {% name %}, application modified to: {% oname %}, cause of failure: {% reson %} ', {'name': 'Heaven and Earth', 'reson ': 'pornographic location '}); // "your tribal name: Heaven and earth. The reason for failure: Porn location"
Php is a little troublesome:
'Heaven and Earth ', 'reson' => 'pornographic '));
Original article address: Small template example. Thank you for sharing it with the original author.