Code

Code block example

The code component can be used to display a block of code with syntax highlighting. In this example the language parameter is defined as php.

class Automobile
    {
        private $vehicleMake;
        private $vehicleModel;

        public function __construct($make, $model)
        {
            $this->vehicleMake = $make;
            $this->vehicleModel = $model;
        }

        public function getMakeAndModel()
        {
            return $this->vehicleMake . ' ' . $this->vehicleModel;
        }
    }

    class AutomobileFactory
    {
        public static function create($make, $model)
        {
            return new Automobile($make, $model);
        }
    }
<!-- code.blade.php -->
<div id="62bedc09051b1" class="c-code" data-uid="62bedc09051a9">
    
    <pre class="c-code__pre"><code class="c-code__output language-php" data-type="php">class Automobile
    {
        private $vehicleMake;
        private $vehicleModel;

        public function __construct($make, $model)
        {
            $this->vehicleMake = $make;
            $this->vehicleModel = $model;
        }

        public function getMakeAndModel()
        {
            return $this->vehicleMake . ' ' . $this->vehicleModel;
        }
    }

    class AutomobileFactory
    {
        public static function create($make, $model)
        {
            return new Automobile($make, $model);
        }
    }</code></pre>
</div>
@code(['language' => 'php', 'content' => ''])
    
    class Automobile
    {
        private $vehicleMake;
        private $vehicleModel;

        public function __construct($make, $model)
        {
            $this->vehicleMake = $make;
            $this->vehicleModel = $model;
        }

        public function getMakeAndModel()
        {
            return $this->vehicleMake . ' ' . $this->vehicleModel;
        }
    }

    class AutomobileFactory
    {
        public static function create($make, $model)
        {
            return new Automobile($make, $model);
        }
    }

@endcode

Blade component parameters

Key Default value Type Available values Description
content Undocumented code... string - -
slot echo 'Whoops, theres no code here. Where is it?' string - -
language php string - -
escape false boolean - -
componentElement div string - -
preTagElement pre string - -
id string - The DOM id of the component.
classList [] array - Array containing wrapping classes array
attributeList [] array - Array containing keys and values rendered as attributes
containerAware false boolean true/false Makes the component container aware. Appends modifiers --size--xs/sm/md/lg to the component.
Settings location: /mnt/persist/www/docroot_styleguide_v2/source/library/source/php/Component/Code/code.json