Jump to content

Displaying script depending on what template page is showing?


n0sleeves
 Share

Recommended Posts

The code is showing just basic echo for example purposes, but I will be replacing them in production with <script></script> tags.  With that said - what am I doing wrong? 

When on the album page, I want the album script to only be referenced in the html head, and when I am on the catalog page I want the catalog script, etc. However, it doesn't appear to be working and is just echoing "album page" on both.  :huh:

<?php
 
		if ($pages->find("template=album")) {
			echo "album page";
		} elseif ($pages->find("template=catalog")) {
			echo "catalog page";
		} 
?>
Link to comment
Share on other sites

if you say need to show a script on multiple templates , then you can use $page->is, like this;

<?php if ($page->is('template=work-index|gallery|videos')) { ?>
scripts here
<?php } ?>

and when you start setting up to use AIOM+, you can then us selectors to load particular scripts with a processwire selector:

<?php $jsfiles  = array('assets/js/plugins.js',
		array('loadOn'  => 'template=work-index', 
			'files'   => array(
			'assets/3rd/dataTables/jquery.dataTables.min.js',
			'assets/3rd/magnific/jquery.magnific-popup.min.js'
			)
		     ),
			'assets/js/main.js',
			'assets/js/vendor/retina.js',
); ?>

<script type="text/javascript" src="<?php echo AIOM::JS($jsfiles); ?>"></script>
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...