URL to javascript file & image file located in single page subdirectory

Permalink
I'm porting a PHP application and trying to instantiate it as a single page named "audio". The existing php script tries to load up a javascript file and a few images located in the audio subdirectory and it's not working. The URL ends up resolving tohttp://www.domain.com/audio/script.js... orhttp://www.domain.com/audio/image.png,... which are not recognized as valid URLs. What is the appropriate approach to include the external JS & Image files?

 
jordanlev replied on at Permalink Reply
jordanlev
Is your "single_page" in a package, or at the top-level of your site?

If it's at the top-level of your site, put your javascript in a top-level "js" folder, and your images in a top-level "images" folder. Then you can load it during your single_page controller's on_before_render() function:
public function on_before_render() {
    $html = Loader::helper('html');
    $this->addFooterItem($html->javascript('your_javascript_file_name.js'));
}


For the images paths, you can put this in your single_page:
<img src="<?php echo DIR_REL; ?>/images/your_image_name.png" />


If your single_page is in a package, then you can do the same basic thing, but the "js" and "images" folders would be inside your package instead of at the top-level of your site. Also you'll need to add your package handle as a 2nd parameter to the $html->javascript() function, like so:
$this->addFooterItem($html->javascript('your_javascript_file_name.js', 'your_package_handle'));

...and for the image, you'll need to do this:
<img src="<?php echo DIR_REL; ?>/packages/your_package_handle/images/your_image_name.png" />


Best of luck!

-Jordan