Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Parsing issues with @image directive. Fatal Error #42

Closed
christianmagill opened this issue Jun 17, 2020 · 5 comments · Fixed by #82
Closed

Parsing issues with @image directive. Fatal Error #42

christianmagill opened this issue Jun 17, 2020 · 5 comments · Fixed by #82
Labels
bug Something isn't working

Comments

@christianmagill
Copy link

christianmagill commented Jun 17, 2020

I've run into parsing issues with the @image directive.

Case 1:

When using the directive as follows:

@image($image_id, 'medium', $alt)

The alt attribute is assigned the literal string "$alt" instead of the variable.

The resulting code ends up being...

<?php echo wp_get_attachment_image(
                $image_id,
                'medium',
                false,
                ['alt' => '$alt']
            ); ?>

Case 2:

When using the directive as follows:

@image($image_id, 'medium', ['alt' => $alt, class='alignright'] )

This one results in a Fatal Error

Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: syntax error, unexpected '','' (T_CONSTANT_ENCAPSED_STRING), expecting ']'

The resulting code is...

<?php echo wp_get_attachment_image(
                $image_id,
                'medium',
                false,
                ['alt' => $alt','class' => 'alignright']
            ); ?>

@christianmagill christianmagill changed the title @image($id, 'size', $alt) sets alt attribute as "$alt" Parsing issues with @image directive. Fatal Error Jun 19, 2020
@Log1x Log1x added the bug Something isn't working label Jul 21, 2020
@ajcsilva
Copy link

Any updates or workarounds for this?

@1pix
Copy link

1pix commented Oct 28, 2022

Hi there,
Any update or possible workaround ?
Tried a lot of combination, still no solution on my side :/
Thanks

probably related to #30

@1pix
Copy link

1pix commented Oct 28, 2022

After trying many things in Log1x\SageDirectives\Util , and saw your big comment in method "isArray" :)

Maybe some ideas here, a bit old, not tested, but putting it here as refs:

No time at the moment but will try if I can.

Cheers and thanks you @Log1x for the huge and so usefull work you do, as ever.

@Log1x Log1x mentioned this issue Jul 29, 2023
@Log1x Log1x closed this as completed in #82 Jul 29, 2023
@thomasjonas
Copy link

Is this issue really solved? I've tried running version 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4 and 2.0.5 but I still get the following error: Uncaught ParseError: syntax error, unexpected single-quoted string ",", expecting "]"

This is in my blade file:

@php
        $alt = $item['logo']['alt'] ? $item['logo']['alt'] : 'Logo';
@endphp

@image($item['logo']['ID'], 'medium', ['alt' => $alt, 'class' => 'h-12 w-auto mix-blend-darken'])

And this is what it compiles to:

 <?php $__imageDirective = $item['logo']['ID']; ?><?php echo wp_get_attachment_image(
                            $__imageDirective,
                            'medium',
                            false,
                            ['alt' => $alt','class' => 'h-12 w-auto mix-blend-darken']
                        ); ?>

The following:

@image($item['logo']['ID'], 'medium', ['alt' => 'alt text', 'class' => 'h-12 w-auto mix-blend-darken'])

compiles to:

<?php $__imageDirective = $item['logo']['ID']; ?><?php echo wp_get_attachment_image(
                            $__imageDirective,
                            'medium',
                            false,
                            ['alt' => 'alt text','class' => 'h-12 w-auto mix-blend-darken']
                        ); ?>

@Log1x
Copy link
Owner

Log1x commented Dec 18, 2024

It was supposed to be but v2.0 was a haul so it's possible it got overlooked. I'd appreciate a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants