Sha256: 064a843e1146504f5f82ca123b3eafdc49f4a4992d5e331a9ddcc5c2e39d46d0

Contents?: true

Size: 1.06 KB

Versions: 8

Compression:

Stored size: 1.06 KB

Contents

# Blocks 

## Installation
Run the following generators to generate the migration files.
```
rails generate headmin:blocks
rails db:migrate
```

## Getting Started

### Setup model

```ruby
class Page < ApplicationRecord
  include Headmin::Blockable
end
```

### Setup forms

The view "headmin/forms/blocks" will render all the form views for the blocks in the database.
A hidden template form will be rendered for all types defined in `allow:`

```erb
# app/views/admin/pages/_form.html.erb
<%= render 'headmin/form', model: [:admin, @page] do |form| %>
  <%= render "headmin/forms/blocks", form: form %>
<% end %>
```

For each type of block you want to include, create a template in `views/admin/blocks`.

### Usage in frontend

```erb
# app/views/website/pages/show.html.erb
<%= render 'headmin/blocks', blockable: @page %>
```

This will render all the blocks associated with the blockable model (e.g. Page).

For each block in the admin, you'll need to create a corresponding template in your frontend.

```erb
# app/views/website/blocks/_contact.html.erb
<%= block.name %>
```

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
headmin-0.2.9 docs/blocks.md
headmin-0.3.4 docs/blocks.md
headmin-0.3.3 docs/blocks.md
headmin-0.3.2 docs/blocks.md
headmin-0.3.1 docs/blocks.md
headmin-0.2.8 docs/blocks.md
headmin-0.2.7 docs/blocks.md
headmin-0.2.6 docs/blocks.md