cancel
Showing results for 
Search instead for 
Did you mean: 

How to call a css file in Phtml magento 2

How to call a css file in Phtml magento 2

Hi guys,

               Here  i have a phtml and css file i.e

home.phtml

path :/var/www/html/gr/app/code/Magestore/Webpos/view/frontend/templates/home.phtml

 

In home.phtml  i was converted html code into js format. I.e below

 

<script type="text/javascript">
document.write('<div class="ms-webpos">');
document.write('<div class="ms-webpos">');
document.write('<div class="login-screen">');
document.write('<div class="wrap-login-form">');
document.write('<form class="form-login" role="form" id="webpos-login" method="post">');
document.write('<h1 class="title-page"><img src="<?php echo $block->getLogoUrl();?>" width="200px" height="200px" alt="logo"/></h1>');
document.write('<div class="form-group wrap-input">');
document.write('<div class="input-box"><input type="text" class="form-control required-entry required" id="username" name="username" placeholder="Username"></div>');
document.write('<div class="input-box"><input type="password" class="form-control required-entry required" id="pwd" name="password" placeholder="Password"></div>');
document.write("</div>");
document.write('<div class="form-group">');
document.write("<button type='submit' class='btn btn-default'><?php echo __('Login');?></button>");
document.write("</div>");
document.write("</form>");
document.write("</div>");
document.write("</div>");
document.write("</div>");
</script>

but the problem is am unable to access the class attribute in div tag.

 

login.css:

path ;/var/www/html/gr/app/code/Magestore/Webpos/view/frontend/web/css/login.css

 

I want to call login.css in home.phtml  ? Can any one guide me on this ?

 

 

 

2 REPLIES

Re: How to call a css file in Phtml magento 2

You can call CSS in the phtml file like below way,

<link rel='stylesheet' href='<?php echo $block->getViewFileUrl("Magestore_Webpos::css/login.css") ?>' />
If Issue Solved, Click Kudos/Accept As solutions.
More info visit Blogs

Re: How to call a css file in Phtml magento 2

i tried but its not working.Actually i wrote html code in between script tag ? I think that is the problem ? what do you say ?