dongqigu0429 2017-02-09 07:40
浏览 36

Symfony twig nl2br

I have twig template and rendering some data in this template, I have two variant

$datatest = "test" . chr(13) . "test"; //nl2br work good
$datatest = "test
test";//nl2br dosn't work, have string in template test
test

and second I have query builder, with select some field

        $qb
        ->select('
            CONCAT(TRIM(s.streetAddress), \'\
\', s.postal, s.postOffice) as company_address
        ')

I try

        $qb
        ->select('
            CONCAT(TRIM(s.streetAddress), CHAR(13), s.postal, s.postOffice) as company_address
        ')

but query builder have error, don't find function CHAR(13), how to create custom DQL for CHAR(13) ?

and in template when dump(data) have string but nl2br not work

enter image description here

I try another filter twig, like this

            <div style="font-size: 8px;">
            {{ data.company_name|upper }}<br>
            {% set address = data.company_address|nl2br %}
            {{ address|upper|raw }}
        </div>

        <br>

        <div style="font-size: 9px;">
            {{ datatest|nl2br }}
        </div>

what need to do in select for nl2br work fine??

  • 写回答

1条回答 默认 最新

  • dongyong5255 2017-02-09 10:31
    关注

    You shouldn't format the output inside the SQL query. You're using an MVC framework, so you should definitely stay within it's concepts - let the presentation be done in the view (a.k.a. template).

    I recommend select and present tha data this way:

    Model:

    $qb->select('s.streetAddress, s.postal, s.postOffice')->from ...
    

    Template:

    {{ streetAddress }}<br>
    {{ postal }} {{ postOffice }}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题