phalcon / cphalcon

High performance, full-stack PHP framework delivered as a C extension.
https://phalcon.io
BSD 3-Clause "New" or "Revised" License
10.76k stars 1.96k forks source link

[BUG]: Can not show HTML title in front. #16026

Closed zikezhang closed 2 years ago

zikezhang commented 2 years ago

Questions? Forum: https://phalcon.io/forum or Discord: https://phalcon.io/discord

Describe the bug Can not show HTML title in front.

To Reproduce

Provide output if related. Provide coredump if any. Use https://docs.phalcon.io/en/latest/generating-backtrace as reference.

Steps to reproduce the behavior: In Controller:

$this->tag->setTitle(' - Welcome to Site');

in the View of volt file:

{{ get_title() }}

it returns empty;

Neither:

{{ title() }}

But:

{{ title('My Title') }}

will show: My Title<title></title> (As you can see, "My Title" is out of the tag).

Jeckerson commented 2 years ago

What is the version of Phalcon?

niden commented 2 years ago

If you are talking about v5 then:

get_title() will use Phalcon\Tag internally so you need to set the title there for it to appear.

title() or tag.title() (both work) uses Phalcon\Html\Helper\Title through the TagFactory. The signature for that is:

title(string $indent = '    ', string $delimiter = PHP_EOL): string

if you cast that to a string then it will print your title. Volt will do that automatically for you. In your last example you are passing My Title as the $indent parameter and this is why it shows up outside the <title> tags.

echo $this->tag->title()->set('My Title');

$this
    ->tag
    ->title()
    ->setSeparator(' : ')
    ->set('APPLICATION')
;
// .....
$this->tag->title()->append("My ");

and in the view

{{ tag.title() }}
zikezhang commented 2 years ago

Thanks, @Jeckerson & @niden . it works well.