Jump to content

Use template for main page and children page?


OpenBayou
 Share

Recommended Posts

Hello,

I'm new to ProcessWire and need help. I have a page called Ad and each page underneath will be a post about a particular advertisement. I want to be able to use different template for the parent page and the children page or can i use one template file and use if parent and if children.

Link to comment
Share on other sites

The usual approach would be an "advertisements" (plural) template for the parent page and an "advertisement" (singular) for the child pages - that will give you the most flexibility in controlling the Family settings so that all child pages must be of that advertisement template when created. There are other approaches, but this will be the simplest/most flexible while you are learning the ropes! 

  • Like 2
Link to comment
Share on other sites

additionally to what @adrian said, it is possible to define those both templates in the admin, one plural and one singular, to build a family out of them. But if you like, you can use one template file for both. If you have created an advertisements.php under site/templates/, create the plural template first. When creating the singular template, select ceate a template without template file in the first screen, (write your singular template name into the input box, without the fileextension). Save, open again and head to the tab [files]. There you select to use an alternative template file, your plural template file. Now you have two templates for easy sort between parent and children, and one templatefile that renders your markup.

If you want to render it the same, do nothing special. If you want to render parent and children different, you can check the template name like

// this block is skipped by child pages
if("advertisements" == $page->temlate) {  // chek for plural / parent template
    // do your stuff ...

return; // end  template file processing here for all parent pages
}

// do your stuff for child pages (single template pages) here, ...
...

 

  • Like 4
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...