Jump to:

23487 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » how do i access fields i have created

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: 735 Views
  • zim
    Avatar
    Community Member
    135 Posts

    how do i access fields i have created Link to this post

    I have created a VideoImage tab on my homepage.php like this

    class HomePage extends Page {
    static $db = array(
    );
    static $has_one = array(
        'VideoImage' => 'Image',
        'VideoTitle' => 'Text',
        'VideoLink' => 'Text'
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();
       
          $fields->addFieldToTab('Root.Content.VideoImage', new ImageField('VideoImage'), 'Content');
          $fields->addFieldToTab('Root.Content.VideoImage', new TextField('VideoTitle'), 'Content');
          $fields->addFieldToTab('Root.Content.VideoImage', new TextField('VideoLink'), 'Content');

    return $fields;
          }

    so I have a video image tab with VideoImage, VideoTitle, VideoLink

    I can't seem to access these now on my HomePage.ss. I thought it would just be $VideoImage.URLSegment, $VideoTitle, $VideoLink but this does not pull in values.

    I have tried $Content.VideoTitle too and does not work. Can anyone point me in right direction. I know must be basic.

  • zim
    Avatar
    Community Member
    135 Posts

    Re: how do i access fields i have created Link to this post

    I have solved this now.

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: how do i access fields i have created Link to this post

    Hi zim!

    I guess your error was in that $has_one array, which was not referencing DataObjects, but it’d be nice to explain the solution you found, for beginners.

    Regards,
    Juan

  • zim
    Avatar
    Community Member
    135 Posts

    Re: how do i access fields i have created Link to this post

    Hey dude i am more than happy to show the solution. i am new to this too and didn't want to look stupid

    this is what I changed it too ... so yes it was the what you say i guess. i put them all onto the main tab in cms as well. it seems to work now so i can now upload a picture title and link and click off to say a youtube vid.. i am currently trying to then get this link to pop youtube link into nice light box.... am trying to use prettyphoto jquery plug in but not working yet.

    class HomePage extends Page {
    static $db = array(
        'VideoTitle' => 'Text',
        'VideoLink' => 'Text'
    );
    static $has_one = array(
        'VideoImage' => 'Image'
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.Content.Main', new ImageField('VideoImage'));
    $fields->addFieldToTab('Root.Content.Main', new TextField('VideoTitle'));
    $fields->addFieldToTab('Root.Content.Main', new TextField('VideoLink'), 'Content');

    return $fields;
    }

    then I can just accesss the fields like this

    <a href="$VideoLink" rel="prettyPhoto"><img src="themes/tutorial/images/home/btn_video_play.png" alt="play"></a>

    <a href="$VideoLink" rel="prettyPhoto">$VideoTitle</a>

    <a href="$VideoLink" rel="prettyPhoto"><img src="$VideoImage.URL" alt="picture"></a>

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