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

dkarthik's avatar

php tags inside blade template

Hi,

Shall we use php tags inside the blade template to assign the value to a variable or to print the form elements?

Ex:

Thanks.

0 likes
6 replies
bestmomo's avatar

Hi,

You can do that because is just a php file, but you should avoid it and manage all data in controller.

1 like
dkarthik's avatar

Thanks bestmomo,

I am managing all the dynamic values in controllers only. I'm having doubt in creating form and html in blade template through Form & HTML providers.

Which is better in the below options ?

{!! Form::text('username') !!} or echo Form::text('username')

dkarthik's avatar

Which is better in the below options ?

{!! Form::text('username') !!} 
or 
<?php  echo Form::text('username') ?>

1 like
phildawson's avatar

@dkarthik They are identical in output, I would go with the {!! !!} inside a blade template as it's shorter. All blade files get compiled and cached until modified too so no need to worry about any overhead. You can see them turned back into <?php echo if you see the cached output in storage/framework/views

The {{ do the same but also wrap the output in e() which itself is a helper function for htmlentities($value, ENT_QUOTES, 'UTF-8', false);

1 like

Please or to participate in this conversation.