Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

2.4.7 Empty headline is still output in the template #166

Closed
Ainschy opened this issue Feb 27, 2024 · 4 comments
Closed

2.4.7 Empty headline is still output in the template #166

Ainschy opened this issue Feb 27, 2024 · 4 comments

Comments

@Ainschy
Copy link

Ainschy commented Feb 27, 2024

Contao 4.13.37 PHP8.2

Since 2.4.7 empty headlines are displayed in the frontend despite a query in the template.

2024-02-27_12h24_53
2024-02-27_12h23_27

@zoglo
Copy link
Contributor

zoglo commented Feb 27, 2024

I was debugging this for the past few minutes and this is because $this->headline is now of type Stringable and not empty in if-clauses anymore.

image

This is being caused in the last change:

$this->Template->headline = new class($this->Template->headline, $this->Template->hl) implements \Stringable
{
public ?string $text;
public ?string $tag_name;
public function __construct(?string $text, ?string $tag_name)
{
$this->text = $text;
$this->tag_name = $tag_name;
}
public function __toString(): string
{
return $this->text ?? '';
}

The question is if this should be fixed from your side @ausi or if every person using custom-elements would need to update their templates after updating to version 2.4.7.

We'd all either need to use <?php if ((string) $this->headline): ?> or there should be a workaround.

I consider this critical since updates would lead to something that may output empty headlines like here:

<div class="ce_rsce_text col-m-6 text block">
	<div class="inside">
		<div class="c_headline">
			<h1></h1>
		</div>
		<div class="c_text">…</div>
	</div>
</div>

A possible solution would be using the ParseTemplateListener as it only renders html templates

namespace App\EventListener;

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\Template;

#[AsHook('parseTemplate')]
class ParseTemplateListener
{
    public function __invoke(Template $template): void
    {
        // Cast stringable to string (See #166)
        $template->headline = (string) $template->headline;
    }
}

@ausi ausi closed this as completed in 61b330c Feb 27, 2024
@ausi
Copy link
Member

ausi commented Feb 27, 2024

@Ainschy can you please try if the latest dev-master version fixes your issue?

@Ainschy
Copy link
Author

Ainschy commented Feb 27, 2024

Thanks it's look fine for me

@ausi
Copy link
Member

ausi commented Feb 27, 2024

Released as version 2.4.8

@Ainschy @zoglo thank you for the quick reporting/debugging/testing!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants