Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

How to get page type.


Reply

5 Posts   2057 Views

Avatar
w1nk5

13 July 2010 at 12:30pm (Last edited: 13 July 2010 12:31pm), Community Member, 25 Posts

I would like to load a footer image depending on the page type. How can I do this?

<% if pagetype = "pagetype" %>
do whatever
<% end_if %>

something like this.

Avatar
w1nk5

13 July 2010 at 12:40pm Community Member, 25 Posts

I figured it out.

<% if RecordClassName = "PageType" %>
do whatever
<% end_if %>

Avatar
TotalNet

13 July 2010 at 1:17pm Community Member, 181 Posts

I was going to say ClassName but both seem to work, I wonder if there's a difference?

Avatar
RichMcNabb

20 November 2010 at 6:34pm Community Member, 34 Posts

Hi,

I am trying to do something similar and display children if they have the jobpage page type. Any help would be much appreciated. Below is the code I have so far:

--------------------------------
JobHolder.ss
--------------------------------
<div class="typography">
   <% if Menu(2) %>
   <% include SideBar %>
   <div id="content">
      <% end_if %>
      <% include PageHeading %>
      $Content
      $Form
      $PageComments
      <% if JobHolder = JobPage %>
         <% control Children %>   
            <div class="job_posting">
               <h2>$JobTitle - $JobLocation</h2>
               <p><strong>Closing date: </strong>$ClosingDate.Nice &nbsp;&#8226;&nbsp; <strong>Contact: </strong>$ContactPerson &nbsp;&#8226;&nbsp; <strong>Phone: </strong>$ContactPhoneNumber &nbsp;&#8226;&nbsp; <strong>Mobile: </strong>$ContactMobileNumber</p>
               <p><strong>Job Details: </strong>$JobDetails.LimitWordCount(50)</p>
               <a href="$Link">Read more...</a></div>
            <div class="clear"> </div>
         <% end_control %>
      <% else %>
         <h2>Available vacacnies</h2>
         <p>There are currently no vacancies available with CDP. No problem, send us your resume so we can get in touch for any future positions you could be perfect for - <a href="mailto:careers@cdp.co.nz">careers@cdp.co.nz</a>.</p>
      <% end_if %>
   <% if Menu(2) %>
</div>
<% end_if %>
</div>

------------------------------------
JobHolder.php
------------------------------------
<?php

class JobHolder extends Page {
static $db = array(
);

static $has_one = array(
);

static $allowed_children = array('JobPage','UserDefinedForm');

function getCMSFields() {
$fields = parent::getCMSFields();
   
    $fields->removeFieldFromTab("Root.Content.Main", "LinkDescription");

return $fields;
}

}

class JobHolder_Controller extends Page_Controller {

}

?>

--------------------------------
JobPage.php
--------------------------------
<?php

/**
* Defines the JobPage page type
*/

class JobPage extends Page {
static $db = array(
'JobTitle' => 'Text',
'JobLocation' => 'Text',
'ClosingDate' => 'Date',
'ContactPerson' => 'Text',
'ContactPhoneNumber' => 'Text',
'ContactMobileNumber' => 'Text',
'JobDetails' => 'HTMLText',
);

static $has_one = array(
'JobDescriptionDownload' => 'File',
);

function getCMSFields() {
$fields = parent::getCMSFields();
   
    $fields->removeFieldFromTab("Root.Content.Main", "Content");
$fields->addFieldToTab("Root.Content.JobPosting", new TextField("JobTitle", "Job Title"));
    $fields->addFieldToTab("Root.Content.JobPosting", new DropdownField('JobLocation','Job Location',singleton('JobLocation')->dbObject('Location')->enumValues()));   
    $fields->addFieldToTab("Root.Content.JobPosting", new DatePickerField('ClosingDate','Application closing date'));
    $fields->addFieldToTab("Root.Content.JobPosting", new TextField("ContactPerson", "Contact person"));
    $fields->addFieldToTab("Root.Content.JobPosting", new TextField("ContactPhoneNumber", "Contact phone number"));
    $fields->addFieldToTab("Root.Content.JobPosting", new EmailField("ContactMobileNumber", "Contact mobile number"));
    $fields->addFieldToTab("Root.Content.JobPosting", new FileIFrameField('JobDescriptionDownload', 'Upload a PDF of the job description'));
    $fields->addFieldToTab("Root.Content.JobPosting", new HtmlEditorField("JobDetails", "JobDetails"));

return $fields;
}
}

class JobPage_Controller extends Page_Controller {

}
?>

Avatar
RichMcNabb

20 November 2010 at 6:52pm Community Member, 34 Posts

Does my JobHolder.php need the following:

static $has_many = array(
"Jobs"=>"Job"
);