Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

inyansuta's avatar

Save a special shape of html code to a database

The following html is stored in the database. This code can be edited by the administrator (html-aware) in the Web Administration (Laravel Nova).

<a href="{{ route('pages.contact') }}">Contact us</a>

When I retrieve this code, I have the following contents (for example) in the $html variable:

<?php
$html = '<a href="{{ route(\'pages.contact\') }}">Contact us</a>';

Does anyone hate to solve how I can now call the next one in the blade?

<?php
{!! $html !!}

This code of course fails (double wrapping the variable in curly braces nested in others curly braces). Perhaps it is understandable what I want to achieve. I just do not know if there is a solution.

0 likes
4 replies
inyansuta's avatar

I figured the use of variables in translation. The example below works, so maybe it's the right way.

$myHtml = ':START_HREF Contact us :END_HREF.'
/* $myHtml is only example, really i have all text stored in laravel translations files and all texts are doubled in database */

In blade I can call now:

{!! trans('texts.my-html', ['START_HREF' => '<a href="' . route('pages.contact') . '">', 'END_HREF' => '</a>']) !!}
Snapey's avatar

you can do something like process the blade elements with $html = view()->render($html) before passing it to the view

Snapey's avatar
Snapey
Best Answer
Level 122

Sorry, last answer is not right. Try this instead;


$html = Blade::compileString('<a href="{{ route(\'pages.contact\') }}">Contact us</a>');

Please or to participate in this conversation.