We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Losing empty line at beginning of textarea (\Phalcon\Tag::textArea())

Phalcon 1.3.3

There is a content which has empty first line. If I set it to textarea, empty first line will be lost.

// first line is empty
$content = <<< EOC

contents line2
EOC;

$this->tag->setDefault('test', $content);
echo $this->tag->textArea(array("test"));

Now \Phalcon\Tag::textArea() render like this:

<textarea  id="test" name="test">
contents line2</tetarea>

I can see on web browser like this:

----------------------
|contents line2
----------------------

I want to see on web browser like this (first emply line):

----------------------
|
|contents line2
----------------------

I researched HTML specs.

In the HTML syntax, a leading newline character immediately following the pre element start tag is stripped.

A single newline may be placed immediately after the start tag of pre and textarea elements. If the element's contents are intended to start with a newline, two consecutive newlines thus need to be included by the author.

So I hope that \Phalcon\Tag::textArea() will render like this:

<textarea  id="test" name="test">

contents line2</tetarea>

What do you think?

Thanks.

html don't render line breaks

you can try:

in php:

echo $this->tag->textArea(nl2br(array("test")));

in volt:

{# nl2br filter #}
{{ "some\ntext"|nl2br }}

Hi, Rafael Gonçalves.

Thank you for your comment.

But I'm talking about value of textarea. I can say the same thing about value of pre element.

Thanks.