Jump to:

3445 Posts in 1031 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » How to access values outside of control

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

Page: 1
Go to End
Author Topic: 2041 Views
  • Hammy
    Avatar
    Community Member
    49 Posts

    How to access values outside of control Link to this post

    How do I get the value $Link to work inside a control?

    Template Section.ss:

       $Link
       <ul>
          <% control FilterColourList %>
             <li><a href="$Link/$ColourName">$ColourName</a></li>
          <% end_control %>
       </ul>

    The first $Link in the template above works fine but when it is inside the control it does not work - it is blank (I assume this is because it is not a field named Link in FilterColourList/FilterColourType.php).

    Is there a way to access the field $Link from Section inside the control of FilterColourList?

    Just in case - here is the php code aswell:

    Section.php

    <?php

    class Section extends Page {
       
       public static $db = array(
          'Tagline' => 'Text'
       );
       
       public static $has_many = array(
          'Detail' => 'Detail'
       );
       
       function getCMSFields() {
          
          $fields = parent::getCMSFields();
          
          $fields->addFieldToTab('Root.Content.Main', new TextareaField('Tagline'), 'Content');      
          $fields->removeFieldFromTab('Root.Content.Main', "MenuTitle");
          $fields->removeFieldFromTab('Root.Content.Main', "Content");
          
          return $fields;
       }
    }

    class Section_Controller extends Page_Controller {
       
       function FilterColourList() {
          $dataObj = 'FilterColourType';
          $filter = '';
          $sort = 'ColourName ASC';
          $join = '';
          $limit = '';
          $ColourList = DataObject::get($dataObj, $filter, $sort, $join, $limit);
          return ($ColourList) ? $ColourList : false;
       }
    }

    ?>

    FilterColourType.php:

    <?php

    class FilterColourType extends DataObject {

       static $db = array(
          'ColourName' => 'Text'
       );
       
       public static $belongs_many_many = array(
          'Detail' => 'Detail'
       );

       function getCMSFields_forPopup() {
          $fields = new FieldSet();
          $fields->push( new TextField( 'ColourName', 'Colour' ) );
          return $fields;
       }
    }

    ?>

  • Fuzz10
    Avatar
    Community Member
    787 Posts
  • Hammy
    Avatar
    Community Member
    49 Posts

    Re: How to access values outside of control Link to this post

    That was exactly what I needed!

    Awesome stuff Fuzz10 - thanks for your help.

  • Capt. Morgan
    Avatar
    Community Member
    30 Posts

    Re: How to access values outside of control Link to this post

    Aww, super. How I have been looking for this. Deserves a bump not to fall out of the first page.

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