[英]How to add variables in a form textarea
I would like to create custom confirmation messages that could be easily updated by the admins.我想创建可由管理员轻松更新的自定义确认消息。
Like喜欢
<textarea>You can contact {contact_name} located at {contact_place}…</textarea>
contact_name and contact_place are fields that will be completed in the same form, and are both required. contact_name 和 contact_place 是将在同一表单中填写的字段,并且都是必填字段。
Is it something easy to manage?管理起来容易吗?
Save the text string with placeholders in db, then use str_replace in custom Helper or in entity virtual fields将带有占位符的文本字符串保存在 db 中,然后在自定义 Helper或实体虚拟字段中使用str_replace
return str_replace(
[
'{{contact_name}}', // placeholders
'{{contact_place}}',
'{{email}}',
],
[
$contact->name, // inputs
$contact->place,
$contact->email,
],
// load template string from db
// You can contact {{contact_name}} located at {{contact_place}}…
$admin->template
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.