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

dgvai's avatar
Level 1

Can I use PHP variables inside <style></style> tag of a blade template?

I am using stylesheet inside my blade template using ... tag. Since I wanted to use variables coming from the controller to use class properties. But I can't use neither {{$var}} nor {!! $var !!} inside style, not even raw Suggest me what else can I do!

0 likes
4 replies
Tray2's avatar

Show us some of your code so we can understand your question better.

dgvai's avatar
Level 1
..... body { font-family: "{!!explode('$',$settings->family)[1]!!}", {{explode('$',$settings->family)[2]}}; padding: 30px !important; }
dgvai's avatar
Level 1

actually in short, I want to use PHP variables inside my blade inside <-style-></-style-> .. is it possible?

dgvai's avatar
dgvai
OP
Best Answer
Level 1

Actually I figured It out that it actually takes PHP variables inside style tag... just there was problem in IDE i was working (VS Code), that showed the error!

Please or to participate in this conversation.