Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » A page head for each section

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

Page: 1 2 3
Go to End
Author Topic: 6690 Views
  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: A page head for each section Link to this post

    Hi,

    I've added your code, but I've error:

    [User Error] Couldn't run query: SELECT `SiteTree`.*, `Page`.*, `GhostPage`.*, `ErrorPage`.*, `RedirectorPage`.*, `VirtualPage`.*, `SiteTree`.ID, if(`SiteTree`.ClassName,`SiteTree`.ClassName,'SiteTree') AS RecordClassName FROM `SiteTree` LEFT JOIN `Page` ON `Page`.ID = `SiteTree`.ID LEFT JOIN `GhostPage` ON `GhostPage`.ID = `SiteTree`.ID LEFT JOIN `ErrorPage` ON `ErrorPage`.ID = `SiteTree`.ID LEFT JOIN `RedirectorPage` ON `RedirectorPage`.ID = `SiteTree`.ID LEFT JOIN `VirtualPage` ON `VirtualPage`.ID = `SiteTree`.ID WHERE (HomepageForDomain REGEXP '(, ^) *localhost *(,|$)') ORDER BY Sort LIMIT 1 | Table 'ss_redconsulting.page' doesn't exist
    GET /silverstripe/?flush=1

  • FireMe!
    Avatar
    Community Member
    74 Posts

    Re: A page head for each section Link to this post

    Hi every one

    I would like to also do this Header Image on a website I am working on, but as some of you know php is not my strong point so, I have added arams code to my class Page extends SiteTree, but I seem to just get a white screen. my code is as follows

    class Page extends SiteTree {
       
       public static $db = array(
       );
       
       public static $has_one = array(
       );

    static $has_one = array (
    'HeaderImage' => 'Image'
    );

    function getCMSFields() {

    $fields = parent::getCMSFields();

    if(!$this->Parent){
    $fields->addFieldToTab("Root.Content.Main", new ImageField('HeaderImage'));
    }

    return $fields;
    }

    }

    Thanks in advance for your help

    FireMe

  • FireMe!
    Avatar
    Community Member
    74 Posts

    Re: A page head for each section Link to this post

    hi got it all working now, but how would I put a fallback image for pages which don't have the header field. for example login page.

    I have tried putting a background image to the Div so if there is no image in the Div you would just see the background image, but it shows the path to the image not selected assets/ any one have any ideas?

    Thanks in advance

    FireMe

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: A page head for each section Link to this post

    in your template, you could use
    <% if HeaderImage %>$HeaderImage<% end_if %>

  • Jeramie
    Avatar
    Community Member
    34 Posts

    Re: A page head for each section Link to this post

    So, in Silverstripe 2.3.3; this code requires a little tweaking. To get it to work for me, I had to insert the code as follows:

    mysite/code/Page.php

    <?php

    class Page extends SiteTree {
       
       public static $db = array(
       );
       
       public static $has_one = array(
          "HeaderImage" => "Image"
       );

       function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Main", new ImageField("HeaderImage"));
    return $fields;
       }

    }

    Of course, I excluded the if statement so that The header image could be chosen per page. I just then placed the following code in my Page.ss file in a div tag for fomatting

    $HeaderImage


    Thanks for all the input on this, I am using this for a friend's site right now so that he doesn't have to figure out how to edit the page.ss file or css files manually.

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: A page head for each section Link to this post

    I'm not getting it.
    I am on 2.3.3

    Do I need to do more than upload the changed Page.php file? and the template with the $HeaderImage code? Where do I add an image? I would like a new tab where the use could upload their own header image for that page

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: A page head for each section Link to this post

    I changed the code to <% if HeaderImage %>$HeaderImage<% end_if %> and ran the dev/build and now things are ok, but still where do I add the header image file?

    I would like to be able to have an added tab where I could upload an image for that specific page. Any help will be appreciated.
    I have the code in the Page.php file and I am not getting an error. When I ran the dev/build it seemed to load a bunch of things. ??? Sorry, I don;t get some of the stuff.

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: A page head for each section Link to this post

    see the 'getCMSFields' function in Jeramie's post?
    this is where the image field is attached to the 'Main' tab of the cms.
    if you want to have a separate tab for the image field, say 'MyImageFieldTab', simply replace 'Root.Content.Main' with 'Root.Content.MyImageFieldTab'

    6690 Views
Page: 1 2 3
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.