My goal is to convert all the blade syntax to PHP.
In my decode.php
I converted almost all my blade syntax, but except one minor thing - the image.
I am not sure how to go around that.
What I have now :
<img src="/img/flags_3/flags/48/{{{ $distributor['hq_country']['name'] or '' }}}.png " width="20px" height="20px">
I am sure that
<?php echo isset( $distributor['hq_country']['name'] ) ? $distributor['hq_country']['name'] : '' ?>
will give me the same result as
{{{ $distributor['hq_country']['name'] or '' }}}
I normally use my blade syntax as part of my HTML attribute, but now I can't use the php code in the HTML attribute.
Any suggestion on this ?
I was wrong. After refreshing the page, it's work. So yes, we can use php code within HTML attribute.
Here is my final code should look like.
<img src="/img/flags_3/flags/48/<?php echo isset( $distributor['hq_country']['name'] ) ? $distributor['hq_country']['name'] : '' ?>.png " width="20px" height="20px">
Something else you may want to consider would be moving the calculation out to it's own line so that it's easier to read:
<?php
$name = '';
if ( isset($distributor['hq_country']['name']) )
$name = $distributor['hq_country']['name'];
?>
{{ "<img src='/img/flags_3/flags/48/$name.png' width='20px' height='20px'>" }}
It's a little more verbose, but when you come back to look at the code months/years from now it will be a bit easier on the eye.
Run your laravel app and it will be rendered to php in \app\storage\views