```ruby
class PageTemplate < Template
  belongs_to :layout
    
  def current_layout
    self.layout || self.design.default_layout
  end
  
  # Returns all widgets, not just those belonging to this template
  # but also those belonging to this page's layout
  def all_widgets
    found_widgets = self.widgets
    found_widgets += self.current_layout.widgets if self.current_layout
  end
  
end```

Change in page template widget data id loading making it more reliable.
user
```ruby
class PageTemplate < Template
  belongs_to :layout
    
  def current_layout
    self.layout || self.design.default_layout
  end
  
  # Returns all widgets, not just those belonging to this template
  # but also those belonging to this page's layout
  def all_widgets
    if self.current_layout
      return self.widgets + self.current_layout.widgets
    else 
      return self.widgets
    end
  end
  
end```
assistant