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.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Simple extension of Page, and template docs

Go to End

7 Posts   1628 Views


Community Member, 6 Posts

25 September 2008 at 2:37pm

Edited: 25/09/2008 2:43pm

I'm pretty new to SS, so forgive my early questions - and the fact that I probably should have posted this in "Extending and Hacking", but it's too late now. Unless a moderator can help me, please? :)

1. Is there a comment syntax in the template language? Am I able to wrap other SS template tags in comments, as I can do in PHP to disable a block of PHP&HTML?


<?php /* 
<?php foo() ; ?> 
*/ ?>

2. The first SS extension I'd like to make is adding an edit view select element to each page, so you can choose a background graphic from a list of uploaded files. This will allow us to have a custom graphic for each content page without requiring the editor to "voodoo" the image into place (requiring correct styling and placement).

I'd appreciate any pointers on how to kick this off.



Forum Moderator, 801 Posts

25 September 2008 at 10:40pm

There's no direct comment syntax, but you can use html comments <!-- --> to hide the generated markup from the browser.

For having selectable banner-images on each page, have a look here:


Community Member, 6 Posts

28 September 2008 at 11:15pm

Edited: 28/09/2008 11:17pm

Thanks Ingo! That did exactly what I wanted. And, like all good recipes, left me hungering for more ... so here are a few more questions ;)

1. In the change I made to Page.php I corrected what seems to be a typo in the recipe - there's a missing closing bracket after 'new ImageField("BannerImage");'

function getCMSFields() {
  $fields = parent::getCMSFields();
  $fields->addFieldToTab("Root.MyBannerImage", new ImageField("BannerImage");
  return $fields;

2. Following just the first stage of that recipe (up to "More Advanced Uses"), each time I visited the MyBannerImage page, the new ImageField() object was saved to the DB, so I ended up with several "new-image" entries in the File table which had to be deleted manually. Do you get this behaviour too? If so, can we add a fix to that recipe please?

3. Wondering how to change the MyBannerImage tab label ... will have a scratch around for this :)

4. I'd also be interested to know how to access just the image URI, rather than the <img > tag, so I can place the image as a CSS background rather than an image element.

Attached is my modified mysite/code/Page.php

Thanks heaps for the pointer!



Community Member, 501 Posts

29 September 2008 at 12:23am

You can access the URI by doing $BannerImage.URL

The tablabel can be changed by changing $fields->addFieldToTab("Root.MyBannerImage", ...
into e.g $fields->addFieldToTab("Root.MyCustomTabLabel", ...

The behavior you described in 2. is weird, haven't experienced that before.


Community Member, 6 Posts

3 October 2008 at 12:45am

beaut, thanks. works a treat.

i forgot to tap the DB update page at first, perhaps i confused it. i'll try the same mod on a fresh SS site soon and see if i can repeat it ...



Community Member, 470 Posts

3 October 2008 at 4:06am

No it's a common bug that has been posted on the forums before. I get it on almost all sites I build.

For now I've just been leaving them alone or manually deleting when I can.


Community Member, 6 Posts

3 October 2008 at 12:56pm

Thanks LeeUmm. I opened a Trac issue - if you can add any input to that (eg how to replicate or links to other forum threads reporting same) then I'm sure it would help debugging.