Jump to content

Checking for a child of a certain template


kathep
 Share

Recommended Posts

Hi all

I am having trouble getting some conditional text to appear based on the presence of a child page with a particular template. Based on this thread, I have used this code:

$childCount = $page->children("template=studentwork_example");

if ($childCount >= 1)
    {$example = "<h2>Examples of Student Work</h2>
<p>Click on any of the images below to see a full example of Parts A and B of the Challenge.</p>";}
else
    {$example = $nbsp;}

The result is that when there is a child page, it looks like this:

post-2947-0-26863400-1461946795_thumb.pn

But when there is no child, the conditional text still displays, like this:

post-2947-0-02815500-1461946794_thumb.pn

Earlier, I also tried this code, with the same result:

if ($page->child)
    {$example = "<h2>Examples of Student Work</h2>
<p>Click on any of the images below to see a full example of Parts A and B of the Challenge.</p>";}

I have added the template selector in my most recent code example (the first one) because I eventually will have multiple child pages using different templates.

My question is: 

Can someone tell me why my conditional text $example is showing up on all pages using this template, irrespective of whether the page has a child page using the template 'studentwork_example'? Where am I going wrong?

Thanks for reading!

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

×
×
  • Create New...