Jump to content

Sub-Templates


bluerobsn
 Share

Recommended Posts

Hi,

I wanted to know if Processwire allows for Sub-Templates?

Example would be if I have a content heavy template, i'd be able to showcase content on various sub-templates of that page.

So mysite.com/bio would be the main page, and if I wanted to a specific piece of content on a page by itself, I'd have a sub-template with mysite.com/bio/location

Hopefully that makes sense.

Thanks!

Link to comment
Share on other sites

You could do this by creating seperate templates for each of those sites. You could devide the content and gather the information from the subsites to show them on the main site or leave all content in the main site in the backend and let the subsites be empty (besides title) and call content from the main template. 

bio (all content saved here)
  - location
  - some other page

or

bio (some content, rest from subpages)
  - location (some content)
  - some other page (more content)

Another way would be without creating separate templates and just using urlSegments on the /bio template. If your templates share parts of the design (markup or logic), than take a look at this topic about including partial content.

Link to comment
Share on other sites

A good example is something like this game site.

http://www.giantbomb.com/etrian-mystery-dungeon/3030-48311/

See how they have tabbed navigation that takes the user to URLs, but it is really just sub-templates.

So if am making a content type that has galleries on every post, but I want to showcase those galleries on separate pages, what is the best method to go about that.

I don't want to have to keep making new sub-templates every time I post.

Link to comment
Share on other sites

I don't want to have to keep making new sub-templates every time I post.

I'm not sure if we're talking about the same thing. You would only once set up a template, which can show a gallery and then use this multiple times. If you're saving the images for the galleries as part of your content-type or as part of the subpages which shows only the gallery is up to you. And if you don't want to create those subpages by hand than have a look at urlSegments. My last post links to a tutorial about it. 

Link to comment
Share on other sites

Yes processwire supports this. But it's not really a sub-template. It's just a child-page using another template and a shared navigation which is as easy as:

<?php
$mainPage = $pages->get('/bio/');

$navPages = $mainPage->children()->append(mainPage);

foreach($navPages as $navPage) {
echo '<a class="tab" href="'.$navPage->url.'">'.$navPage->title.'</a>';
}

?>

Structure could be like this:

bio (using "bio" template(url for this child page would be /bio/))
  - location (using "location" template (url for this child page would be /bio/location/))
  - some other page (using another template (url for this child page would be /bio/some-other-page/))
Link to comment
Share on other sites

Yea, not sure if we are on the same page. So I am not looking for the URL to control the data, rather just act as a template signifier to use a different sub-template.

I am trying to do something like this http://www.webhook.com/docs/pages-and-templates/#sub-templates

So my base content url (mysite.com/some-game) shows whatever is in my base template html, and then my sub template for that same post (mysite.com/some-game/gallery) would show whatever html I have in that sub template. I can basically put whatever content I want in both of them. I just need my site to follow that a /gallery sub template exists and render it after the base content url.

I feel like this sounds way more complicated than it is lol.

Thanks for your help. I appreciate it.

Link to comment
Share on other sites

As it is your first appearence in the forums, bluerobsn (greetings, by the way :)), I suggest you may be new to the way PW works in general and its terminology. So maybe you are asking about very different thing. If it is not the case, sorry. Just ignore everything below.

In Processwire all data from all pages is accessible via api from each template file. So you can get content from any page from any other page and use it there. Just get your head around all this, go through a tutorial or two and it'll make sense.

  • Like 5
Link to comment
Share on other sites

yes, the helloworld tutorial is a good starting point!

thereafter you can easily setup a kind of "sub-template-system" (how you call it) like this:

post-2137-0-32889800-1429352733_thumb.pn

this is the "default intermediate edition" profile - just install this on your dev-environment and read the files _main.php, _init.php and basic-page.php and you will understand how easy it is to setup very flexible and custom things with processwire!

also welcome to the forum :)

ps: actually you would only have to append "<?php" on top of _init.php and all your template files - everything else is ready to use!

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