n0sleeves Posted May 28, 2014 Posted May 28, 2014 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. <?php if ($pages->find("template=album")) { echo "album page"; } elseif ($pages->find("template=catalog")) { echo "catalog page"; } ?>
adrian Posted May 28, 2014 Posted May 28, 2014 What you want is: if($page->template == 'album'){ The $page variable is the current page in PW, so this returns the template for this page. 3
Macrura Posted May 28, 2014 Posted May 28, 2014 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> 3
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now