Martin Muzatko Posted November 25, 2014 Share Posted November 25, 2014 Hi there! I'm trying to include various size-intense files, like JS libraries, only when needed. I do this in _main.php, so when I render subpages with a component needed, I need to access that via $page->children() and $page. (only maximum 1 level deep. $page->children()->has('field=slider'); Full Codeexcerpt: <?php // COMPONENTS if ($page->children()->has('slider')) { include 'components/slick.php'; } ?> I'm not exactly sure if I'm doing it right with the selector. I saw both field= and just the fieldname ('slider'). I have no idea if 'slider' alone is enough; Help is appreciated Cheers,Martin Link to comment Share on other sites More sharing options...
kixe Posted November 25, 2014 Share Posted November 25, 2014 $page is always the current page if ($page->has('slider')) echo '<script src="path"></script>'; Link to comment Share on other sites More sharing options...
RyanJ Posted November 25, 2014 Share Posted November 25, 2014 Is slider an image field? You can loop through each child and check the fields count with something like this. foreach($page->children as $child) { if (count($child->slider)) { include 'components/slick.php'; } } Link to comment Share on other sites More sharing options...
Martin Muzatko Posted November 25, 2014 Author Share Posted November 25, 2014 Is slider an image field? You can loop through each child and check if the field is not empty with something like this. foreach($page->children as $child) { if (count($child->slider)) { include 'components/slick.php'; } } It's a repeater fiield. I'll try what you suggested. Thanks! Link to comment Share on other sites More sharing options...
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