Fabian asked:

controller/template MVC style

I'm a bit confused about the relationshop between the controller and the template when rendering pages. Lets say I have a simple template (foo.xhtml):

<html>
  <head>
    <title>#{title}</title>
  </head>
  <body>
      #{content}
  </body>
</html>
I now I can fill the template by using the tags:
<?r
title = 'Page title'
content = 'Some content...'
?>
However, sometimes I feel it would be nicer to put the programming logic in a separate space (MVC style). So I create a controller:
class MyController < Nitro::Controller
  def foo
    title = 'Page title'
    content = 'Some content...'
    %[
    <html>
      <head>
        <title>#{title}</title>
      </head>
      <body>
        #{content}
      </body>
    </html
    ]
  end
end
This moves both the programming logic and the template data into the same space, but I want them separated, like this:
class MyController < Nitro::Controller
  def foo
    title = 'Page title'
    content = 'Some content...'
    # pass title and content too foo.xhtml and render the template
  end
end
How do I acomplish this within Nitro? Is it possible?

(1 attempts)

Fabian answered:

You're almost there.

MVC-style:

Controller (C) controller.rb:

class MyController < Nitro::Controller
  def foo
    @title = 'Page title'
    @content = 'Some content...'
  end
end

Template (View/V) foo.xhtml:

<html>
  <head>
    <title>#{@title}</title>
  </head>
  <body>
      #{@content}
  </body>
</html>

Rating: 4