Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » How to get page type.

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

Page: 1
Go to End
Author Topic: 2036 Views
  • w1nk5
    Avatar
    Community Member
    25 Posts

    How to get page type. Link to this post

    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.

  • w1nk5
    Avatar
    Community Member
    25 Posts

    Re: How to get page type. Link to this post

    I figured it out.

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

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: How to get page type. Link to this post

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

  • RichMcNabb
    Avatar
    Community Member
    34 Posts

    Re: How to get page type. Link to this post

    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 {

    }
    ?>

  • RichMcNabb
    Avatar
    Community Member
    34 Posts

    Re: How to get page type. Link to this post

    Does my JobHolder.php need the following:

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

    2036 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.