 
     super options, data
 
-    @addSubView @container = new KDCustomHTMLView cssClass: 'content-container'
+    @addSubView @container  = new KDCustomHTMLView
+      cssClass: 'content-container'
+
     @machine = @getData()
 
     return @handleNoMachineFound()  unless @machine
 
-    {jMachine}   = @machine
+    { computeController } = kd.singletons
+
+    { jMachine } = @machine
+    { @state }   = @machine.status
+
+    @machineId   = jMachine._id
+    @isManaged   = jMachine.provider is 'managed'
+    @templateId  = jMachine.generatedFrom?.templateId ? null
     @machineName = jMachine.label
-    @machineId   = jMachine._id
-    {@state}     = @machine.status
-    @isManaged   = @machine.provider is 'managed'
 
     @showBusy()
     @show()
 
-    {computeController, marketingController} = kd.singletons
-
     computeController.fetchUserPlan (plan) =>
       @userSubscription = plan
 

    computeController.on "start-#{@machineId}", @bound 'updateStatus'
    computeController.on "build-#{@machineId}", @bound 'updateStatus'
    computeController.on "stop-#{@machineId}",  @bound 'updateStatus'

    # Stack build events
    if stack = computeController.findStackFromMachineId @machine._id
      computeController.on "apply-#{stack._id}", @bound 'updateStatus'

    computeController.on "reinit-#{@machineId}", (event) =>
      @updateStatus event, 'reinit'


      kd.warn err  if err?

      return @buildVerifyView()  unless verified


      if @stack # Stack build events
        computeController.on "apply-#{@stack._id}", @bound 'updateStatus'

      kd.singletons.paymentController.subscriptions (err, subscription) =>
        kd.warn err  if err?
        if subscription?.state is 'expired'
        then @buildExpiredView subscription
        else @buildInitial()

    { marketingController } = kd.singletons
    marketingController.on 'SnippetNeedsToBeShown', @bound 'showMarketingSnippet'

    @on 'MachineTurnOnStarted', (machine) ->
      sendDataDogEvent 'MachineTurnedOn', tags: {label: machine.label}


