Kurt Liu
Kurt Liu

Reputation: 630

How do I stop slim template rendering half way?

I am using Sinatra and slim. In one slim template I would like to stop render if a variable is true. Code like this:

- if @lock
    p.alert this page is locked.
    - stop_render

I tried to use return and that just generated a empty page. Apparently a plain return does not keep the html markup slim just rendered. so is there a way to stop render a template halfway and keep the rendered content?

Upvotes: 0

Views: 267

Answers (1)

trushkevich
trushkevich

Reputation: 2677

Consider putting the part of your template that you don't want to render into a partial and then render it conditionally:

- if @lock
  p.alert
    | This page is locked.
- else
  = slim :'partials/_my_partial'

Upvotes: 2

Related Questions