Accessing view properties in Space Pen content?


I feel like I must be missing something obvious here. I want to be able to access a view’s properties from within its @content template, but I can’t seem to figure it out:

class InstallPanel extends View
  @content: ->
    @div =>
      @div class: 'section packages', =>
        @div class: 'section-container', =>
          @div class: 'text native-key-bindings', tabindex: -1, =>
            @span class: 'icon icon-question'
            @span "#{@searchType} are published to "

@searchType is defined in the initialize method.

You can see that in the last line I’m trying to access it in the string, but it’s looking for it on the wrong value of this. I’ve tried changing @content to be a fat arrow function, and tried explicitly assigning the correct value of this to a variable before @content, but so far nothing’s worked.


AFAIK you can’t, @content is a class level method so it doesn’t access instances properties or methods.

However, you’ll receive the constructor/initialize arguments in the @content method, so if @searchType is a derived property of these arguments you can expose a method at the class level that compute the value of searchType using the provided arguments and use that method both in @content and in initialize.

Another way would be to specify an outlet on the span where searchType should be displayed and affect the value in the initialize method.