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.

Template Questions /

A page head for each section


Reply


24 Posts   7007 Views

Avatar
biapar

Forum Moderator, 435 Posts

22 June 2009 at 7:34pm

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

Avatar
FireMe!

Community Member, 74 Posts

10 July 2009 at 6:18am

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

Avatar
FireMe!

Community Member, 74 Posts

2 August 2009 at 4:46am

Edited: 02/08/2009 4:48am

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

Avatar
schellmax

Community Member, 126 Posts

3 August 2009 at 8:49pm

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

Avatar
Jeramie

Community Member, 34 Posts

10 October 2009 at 5:08am

Edited: 10/10/2009 5:10am

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.

Avatar
steve_nyhof

Community Member, 224 Posts

28 October 2009 at 2:11pm

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

Avatar
steve_nyhof

Community Member, 224 Posts

28 October 2009 at 2:12pm

Edited: 28/10/2009 2:24pm

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.

Avatar
schellmax

Community Member, 126 Posts

28 October 2009 at 10:53pm

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'