kimbl kimbl - 1 month ago 9x
HTML Question

$variable in style="background-image: url:( );"

I have a question for using a

as IconPath for setting an
background-image: url()

<div style="background-image: url($iconPath)"></div>

I have no idea how I can set the url for the background-image with a variable?

I tried with

Has anyone an idea?


PHP is a server side language, so if you want anything to be visible to DOM (i.e to your HTML), you will have to print it to DOM.This is achieved through echo

<div style="background-image: url('<?php echo $iconPath ?>')"></div>

Any variable value if needed to be printed, just echo it and it'll be visible to DOM.