Jump to content

Recommended Posts

Posted

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

Posted

$page is always the current page

if ($page->has('slider')) echo '<script src="path"></script>';
Posted

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';
     }
}
Posted

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!

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
  • Recently Browsing   0 members

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