duanlu0075 2017-05-18 21:32
浏览 25

如何将变量分配给TWIG中另一个变量的值

I am using a PHP product called Mautic which leverages the TWIG template language.

They have some tokens that are accessed similar to

{subject}

and

{contactfield=company}

I want to be able to use the | raw function but when I try

{contactfield=company | raw}

it breaks on me.

If I set a variable then I can use the double curly braces and the functions like raw.

So I am thinking that I need to set a variable to the contactfield=company and then I can access it via the double curly braces. This is how I tried to do it but no luck.

{% set myvar = contactfield=company %}

I tried to use the dump() to guess at what the variable name might be in the context but it appears that command is disabled.

I'm not sure what the syntax should be.

UPDATE

I ran the following code

<ol>
    {% for key, value in _context %}
      <li>{{ key }}</li>
    {% endfor %}
</ol>

and got this result

  1. isNew
  2. slots
  3. content
  4. email
  5. template
  6. basePath
  7. app
  8. cfos
  9. _parent

I suspect that the {contactfield=company} is probably some shorthand for an attribute on one of these variables but not sure how I can dig into the top level context variables to see what other data may be lurking underneath.

I tried using {{dump()}} in the template but that seems to be disabled.

If I knew how to inspect these top level variables I might be able to figure out where this information lives. Unfortunately I don't have access to the PHP environment so I have to discover the information through trial and error.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python变量和列表之间的相互影响
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)