hi guys,
Here i have two phtml files i.e
home.phtml:
path: /var/www/html/gr/app/code/Magestore/Webpos/view/frontend/templates/home.phtml
code :
<script type="text/javascript">
var nwIp4= "192.168.0.4";
window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var pc = new RTCPeerConnection({iceServers:[]}), noop = function(){};
pc.createDataChannel("");
pc.createOffer(pc.setLocalDescription.bind(pc), noop);
pc.onicecandidate = function(event)
{
var s = event.candidate.candidate;
var result = s.split(" ");
var nwIp1 = result[4];
var mIp= 'nwip='+nwIp1;
if(nwIp1 == nwIp4)
{
//here i want to call login.phtml in magento 2
}
}
</script>
login.phtml:
path : /var/www/html/gr/app/code/Magestore/Webpos/view/frontend/templates/login.phtml
and now i want to call login.phtml file in home,phtml within script tag.
can any one help me on that ?
Solved! Go to Solution.
Hi @bharath553
Use this code to call phtml file in script
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magestore_Webpos::login.phtml")->toHtml() ?>
If you have custom block for phtml then use block
<?php echo $this->getLayout()->createBlock("Magestore\Webpos\Block\MyBlock")->setTemplate("Magestore_Webpos::login.phtml")->toHtml() ?>
So you final code will look like this
if(nwIp1 == nwIp4) { <?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magestore_Webpos::login.phtml")->toHtml() ?> }
If Issue Solved, Click Kudos/Accept As solutions.
you can use following code
<?php echo $this->getLayout()->createBlock("QaisarSatti\HelloWorld\Block\HelloWorld")->setTemplate("QaisarSatti_HelloWorld::helloworld.phtml")->toHtml(); ?>
Hi @bharath553
Use this code to call phtml file in script
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magestore_Webpos::login.phtml")->toHtml() ?>
If you have custom block for phtml then use block
<?php echo $this->getLayout()->createBlock("Magestore\Webpos\Block\MyBlock")->setTemplate("Magestore_Webpos::login.phtml")->toHtml() ?>
So you final code will look like this
if(nwIp1 == nwIp4) { <?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magestore_Webpos::login.phtml")->toHtml() ?> }
If Issue Solved, Click Kudos/Accept As solutions.
code:
----------
<script type="text/javascript">
var nwIp4= "192.168.0.4";
window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var pc = new RTCPeerConnection({iceServers:[]}), noop = function(){};
pc.createDataChannel("");
pc.createOffer(pc.setLocalDescription.bind(pc), noop);
pc.onicecandidate = function(event)
{
var s = event.candidate.candidate;
var result = s.split(" ");
var nwIp1 = result[4];
if(nwIp1 == nwIp4)
{
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magestore_Webpos::login.phtml")->toHtml(); ?>
}
}</script>
after implementing the above code result is :
-------------------------------------------------------------
Hi Mr patel your code is working fine but with in script tag its not working.Out of script tag its working good. can you help me on that ?
you can use following code
<?php echo $this->getLayout()->createBlock("QaisarSatti\HelloWorld\Block\HelloWorld")->setTemplate("QaisarSatti_HelloWorld::helloworld.phtml")->toHtml(); ?>
<?php
echo $this->getLayout()->createBlock("QaisarSatti\HelloWorld\Block\HelloWorld")->setTemplate("QaisarSatti_HelloWorld::helloworld.phtml")->toHtml();
?>
the above calling method is right but its not working inside script tag
code:
--------
<script type="text/javascript">
var nwIp4= "192.168.0.4";
window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var pc = new RTCPeerConnection({iceServers:[]}), noop = function(){};
pc.createDataChannel("");
pc.createOffer(pc.setLocalDescription.bind(pc), noop);
pc.onicecandidate = function(event)
{
var s = event.candidate.candidate;
var result = s.split(" ");
var nwIp1 = result[4];
if(nwIp1 == nwIp4)
{
<?php
echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magestore_Webpos::login.phtml")->toHtml();
?>
}
}
</script>