I defined a function in a block class as below to return the contents of an entire custom JS file, the path of which is stored in $absolute_custom_js_file_path
. What is the right PHP function to be used inside the return statement so that my phtml file would get all the JS file contents? Thanks for the help.
public function getAllPagesJSContent() {
// Code to get the absolute path to the media directory.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$fileSystem = $objectManager->create('\Magento\Framework\Filesystem');
$mediaPath = $fileSystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->getAbsolutePath();
// Code to get the absolute path to the custom JS file.
$absolute_custom_js_file_path = $mediaPath . 'pmm-custom/allpages.js';
return __('What PHP function to use to read and return the contents of the JS file)');
}
Here is the phtml:
<?php
echo $block->getAllPagesJSContent();
?>
getAllPagesJSContent()
is going to be called by another custom JS file. – CodeForGood May 12 '20 at 10:50