colinlongworth's avatar

Escaping php tags in blade for code highlighting?

I'm trying to build a blade view that will show some code for a user to copy and paste. The issue is that the code snippet contains a <?php tag, hence it's being executed.

Is there any way to tell Blade to ignore those tags?

<pre>
<code class="language-php">
<script>
window.dsSettings = {
        appId: 'REPLACE WITH YOUR APP ID',
        name: '<?php echo "{$user->first_name} {$user->last_name}"; ?>;',
    };
</script>   
</code>
</pre>
0 likes
5 replies
colinlongworth's avatar

@MohamedTammam Close, but it still sees "$user->first_name" as a valid parameter (It's not). On the system the user will copy and paste the code to, it will be valid.

In other words, the entire line needs to be echo'd verbatim

Edit: Not sure what you mean by 'remove spaces', the backslashes appear in the mark up.

colinlongworth's avatar

This is how I solved it, thank you to @mohamedtammam for the direction.

@php
    $name = '<?php echo "{$user->first_name} {$user->last_name}"; ?>';
@endphp

name: '{{ $name }}',

Please or to participate in this conversation.