17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2788 Views |
-
problem creating subtemplate

10 November 2007 at 1:48am
Hi. I downloaded SS and I love it. It works great. I'm trying to learn more tricks and here is one I have problem with.
I read the tutorial on creating a sub templates. I tried to follow it but no luck. I understand the concept but can't make it work. What I need is a template for my event page so it will show the instances of my events from the event section. My be up to 10 latest events. I can do it with includes on my main template but then it appears on all pages. Thank you in advance. -
Re: problem creating subtemplate

10 November 2007 at 2:14am Last edited: 10 November 2007 2:15am
Hi there,
What you need is a specific page type for your event pages - for example, EventPage. Once you have an EventPage.php file inside mysite/code with a structure like this:
class EventPage extends Page {
}
class EventPage_Controller extends Page_Controller {
}
...And then run db/build?flush=1 then the EventPage page type will be available to you via a dropdown in the CMS when you click the 'Create' button.
If you want this EventPage to have it's own specific sub-template, then you create EventPage.ss inside templates/Layout/ - also remember to place ?flush=1 at the end of the URL once you've added a template because SilverStripe doesn't automatically know when you've added new templates/code.
Hope this helps,
Cheers,
Sean -
Re: problem creating subtemplate

10 November 2007 at 3:52am Last edited: 10 November 2007 2:39pm
Hi Sean. Thank you for responding to my post.
Thanks to you I successfully created an events page however I'm not sure how to make the includes and controls to work on it. For instance I have this code on my other pages:
<% include Blog %>
and this
<div id="rightSecHead_"><h1>Blog</h1></div>
<div id="rightSecContent_">
<% control ChildrenOf(blog) %>
<h2>$Title</h2>
<p>$Content.LimitWordCount(10)
<a href="$Link"> more </a></p>
<% end_control %>I included the above code in the template but no effect.
Also I don't see my new page in the drop down list of content pages. I tried to ?flush=1 many times but it does not seem to take an effect. Also page does not have any of the meta tags that are generated by $MetaTags. It seems like I'm in the wrong directory. I would appreciate your help. Thank you.
-
Re: problem creating subtemplate

17 November 2007 at 2:30pm Last edited: 17 November 2007 2:37pm
Here's a quick checklist for creating new page-types:
1. Create EventPage.php in mysite/code
2. Ensure EventPage.php has the following structure:
[code php]
class EventPage extends Page {}
class EventPage_Controller extends Page_Controller {}
3. Add db/build?flush=1 to the end of your URL, for example: mysite.com/db/build?flush=1. This is required to be run first before you can see an EventPage in the dropdown for creating a new page, or changing the current page-type of an existing one.
4. If you need a specific template for EventPage other than Page.ss, create a new sub-template for the EventPage class called EventPage.ss in mysite/templates/Layout/. You also need to add ?flush=1 to the end of the URL so SilverStripe picks up your new template.
Hope this helps!
Sean
| 2788 Views | ||
|
Page:
1
|
Go to Top |


