Magento – How to add JS and CSS calling in PHTML file

javascriptmagento2phtml

I am including JS validations in Magento, there respected .js and .css files included like:

app/design/frontend/Smartwave/porto/Smartwave_Porto/layout/default.xml

<css src="Smartwave_Porto::css/index.css"/>
<script src="Smartwave_Porto::js/index.js"/>

and include those css, js files in :

app/design/frontend/Smartwave/porto/Smartwave_Porto/web/css and js

I have created a CMS Page and call the test.phtml file in cms page

I want to include css and js files in the test.phtml file but I cant.

Explain how to inlude those css and js files in .phtml file
Location of .phtml file:

app/design/frontend/Smartwave/porto/Smartwave_Porto/templates/test.phtml

Thanks!

Best Answer

You can follow the bellow technique.

enter image description here

You can also get static file location url directly:-

$block->getViewFileUrl();