Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Simple extension of Page, and template docs

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

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

Page: 1
Go to End
Author Topic: 1361 Views
  • xurizaemon
    Avatar
    Community Member
    6 Posts

    Simple extension of Page, and template docs Link to this post

    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?

    like,

    <?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.

    Thanks!

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Simple extension of Page, and template docs Link to this post

    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: http://doc.silverstripe.com/doku.php?id=imageupload

  • xurizaemon
    Avatar
    Community Member
    6 Posts

    Re: Simple extension of Page, and template docs Link to this post

    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!

    Cheers

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Simple extension of Page, and template docs Link to this post

    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.

  • xurizaemon
    Avatar
    Community Member
    6 Posts

    Re: Simple extension of Page, and template docs Link to this post

    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 ...

    cheers!

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: Simple extension of Page, and template docs Link to this post

    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.

  • xurizaemon
    Avatar
    Community Member
    6 Posts

    Re: Simple extension of Page, and template docs Link to this post

    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.

    http://open.silverstripe.com/ticket/2893

    Cheers

    1361 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.