Created
November 23, 2020 20:06
-
-
Save edgrosvenor/8acc43ee32edb45cfb679fdecac52117 to your computer and use it in GitHub Desktop.
Displaying blade component tags in a code block in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\View\Components; | |
use Illuminate\View\Component; | |
class CodeBlock extends Component | |
{ | |
/** | |
* Create a new component instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
} | |
/** | |
* Get the view / contents that represent the component. | |
* | |
* @return \Illuminate\Contracts\View\View|string | |
*/ | |
public function render() | |
{ | |
return function($data) { | |
return '<code><pre>' . | |
str_replace(['<x-', '</x-'], ['<x-', '</x-'], (string) $data['slot']) | |
. '</code></pre>'; | |
}; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<x-code-block> | |
@verbatim | |
<x-sentence class="classy"> | |
This will display the contents of the code block as expected without attempting to compile the sentence component. | |
</x-sentence> | |
@endverbatim | |
</x-code-block> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment