首页 > 解决方案 > Liquid:用表达式替换字符串

问题描述

我需要用表达式替换字符串。该代码具有三个字符串替换方案。对于前两个,字符串被替换为备用字符串,效果很好。但是对于第三种情况,我需要用一个表达式替换字符串“channel”:{{ booking.channel }}。我的代码仅对第三个实例不正确,我还没有找到解决方案。

<div class="row">
          <div class="left title">Source</div>
          <div class="right">{{ booking.source | replace: "app", "Front Desk" | replace: "widget", "Website" | replace: "channel", {{ booking.channel }} }}</div>

标签: stringobjectliquid

解决方案


您需要移除{{ }}arround booking.channel,因为您已经在 other 内部{{ }}

<div class="row">
    <div class="left title">Source</div>
    <div class="right">{{ booking.source | replace: "app", "Front Desk" | replace: "widget", "Website" | replace: "channel", booking.channel }}</div>

推荐阅读