0

I've installed livereload and have it working inside of my theme, but there's a problem if I want to use this theme on another server.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="css/mystyle.css" />
        <script src="http://{myipaddress}:35729/livereload.js" src_type="url"></script>
    </head>
</page>

{myipaddress} = the IP address of the server.

How can I programmatically enable/disable livereload and change the IP address based on the server address. I know I can use $_SERVER['SERVER_ADDR'], but where and how can I insert this logic?

EDIT

I've added the following to my default.xml body.

<referenceContainer name="after.body.start">
  <block class="Myvendor\Mytheme\Block\Js\Livereload" name="livereload-config" template="Myvendor_Mytheme::js/livereload.phtml"/>
</referenceContainer>

And then created the corresponding block and template file. Fairly simple, but I just didn't think of it.

2
  • 1
    This is not recommended way But I think you can insert script in your header.phtml template and than where you can make it dynamic IP as per your need.
    – anonymous
    Jun 18, 2018 at 8:30
  • You gave me an idea. Maybe I can just add this to a block and insert via layout/default.xml after body start. I'll try it out
    – Toine H
    Jun 18, 2018 at 8:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.