Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » access the variables from a parent out of an <% control ?

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

Page: 1
Go to End
Author Topic: 960 Views
  • benni91
    Avatar
    Community Member
    72 Posts

    access the variables from a parent out of an <% control ? Link to this post

    Hey @ all,

    If got a problem.

    i build this page

    Reference.ss

    <% control Screens %>
       <div class="refimg">
          <a href="$Screen.url" rel="lightbox-$Title" title="$Description">$Screen.setWidth(430)</a>
       </div>
    <% end_control %>
    <div class="clear"></div>

    Reference.php

    <?php
    class ReferencePage extends Page {
          
       static $allowed_children = 'none';
       static $default_parrent = 'referenzen';
       static $can_be_root = false;

       public static $db = array(
          'Date' => 'Date',
          'Category' => 'Text',
          'Site' => 'Text'
       );

       public static $has_one = array(
          'Client' => 'ClientObject',
          'Preview' => 'Image'
       );
       
       public static $has_many = array(
          'Screens' => 'ScreenObject'
       );

       function getCMSFields() {
          
          $fields = parent::getCMSFields();
          
          $fields->addFieldToTab('Root.Content.Main', $date = new DateField('Date', 'Release Date'), 'Content');
          $date->setConfig('showcalendar', true);
          
          $fields->addFieldToTab('Root.Content.Main', new TextField('Category','Web/Print/Hosting etc.'), 'Content');
          $fields->addFieldToTab('Root.Content.Main', new TextField('Site','Link zur Online Referenz (Website wenn online)'), 'Content');
          
          $clients = DataObject::get('ClientObject')->toDropDownMap('ID', 'Name');
          $fields->addFieldToTab('Root.Content.Main', new DropdownField('ClientID', 'Client', $clients, $this), 'Content');
          
          $fields->addFieldToTab('Root.Content.Screens', new ImageDataObjectManager($this, 'Screens', 'ScreenObject', 'Screen', array('Description' => 'Beschreibung'), 'getCMSFields_forPopup'));
          
          $fields->addFieldToTab("Root.Content.Preview", new ImageField('Preview', 'Preview Image 276px x 140px'));
          
          return $fields;
          
       }

    }
    class ReferencePage_Controller extends Page_Controller {

    }

    ?>

    and

    ScreenObject

    <?php
    class ScreenObject extends DataObject {

       public static $db = array(
          'Description' => 'Text'
       );

       public static $has_one = array(
          'Screen' => 'Image',
          'ReferencePage' => 'ReferencePage'
       );

       public function getCMSFields_forPopup() {

    return new FieldSet(
    new TextField('Description', 'Beschreibung'),
    new ImageField('Screen', 'Screenshot')
    );

    }
       
    }

    ?>

    I'm trying to get the page title of my ReferencePage
    (<a href="$Screen.url" rel="lightbox-$Title" title="$Description">$Screen.setWidth(430)</a>)

    But i just get the image title.

    if i try it like this

    <% control Screens %>
       <div class="refimg">
          <a href="$Screen.url" rel="lightbox-<% control Parent %>$Title<% end_control %>" title="$Description">$Screen.setWidth(430)</a>
       </div>
    <% end_control %>
    <div class="clear"></div>

    it also didn't work :/

    any solutions?

    Thanks Benni

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: access the variables from a parent out of an <% control ? Link to this post

    You can use $Parent.Title or $Top.Title to temporally escape out of the control.
    http://doc.silverstripe.org/sapphire/en/reference/built-in-page-controls#top

  • benni91
    Avatar
    Community Member
    72 Posts

    Re: access the variables from a parent out of an <% control ? Link to this post

    Thx, $Top.Title works
    $Parent.Title didn't

  • geoffmcqueen
    Avatar
    Community Member
    11 Posts

    Re: access the variables from a parent out of an <% control ? Link to this post

    The syntax now is "$Up.Title" instead of $Parent. I'm sure it made sense to someone to change something that already worked and lead to confusion and re-writing of templates...

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