Sha256: d0fe8af064a048f1a20fe2dbe02e0566583ad194dfea3ede97403345530d0e78

Contents?: true

Size: 1.22 KB

Versions: 13

Compression:

Stored size: 1.22 KB

Contents

= Cells

As explained in dedicated page xref:develop:view_models_aka_cells.adoc[View Models (Cells)], a cell is an object that represent a fragment of your UI.

In order to define a cell, you need to create a class that inherits from `Decidim::ViewModel` in your module.

Cells classes are located in the `app/cells/decidim/<my_module>` directory, and named: `<my_cell>_cell.rb`.

For example, if you want to create a cell that renders a simple text:

```ruby
# frozen_string_literal: true

# app/cells/decidim/my_module/my_cell_cell.rb
module Decidim
  module MyModule
    class MyCellCell < Decidim::ViewModel

      def show
        render if condition?
      end

      private

      def condition?
        true
      end
    end
  end
end
```

Then, you can render the cell in your view:

```erb
<%= cell("decidim/my_module/my_cell") =>
```

== More information

* https://github.com/trailblazer/cells/blob/master/README.md[cells/README.md at master ยท trailblazer/cells]
* http://trailblazer.to/gems/cells/[Trailblazer: Cells] / http://trailblazer.to/gems/cells/api.html[Trailblazer: Cells API]
* https://www.sitepoint.com/introduction-to-cells-a-better-view-layer-for-rails/[Introduction to Cells: A Better View Layer for Rails -- SitePoint]

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-0.29.1 docs/modules/develop/pages/classes/cells.adoc
decidim-0.28.4 docs/modules/develop/pages/classes/cells.adoc
decidim-0.29.0 docs/modules/develop/pages/classes/cells.adoc
decidim-0.28.3 docs/modules/develop/pages/classes/cells.adoc
decidim-0.29.0.rc4 docs/modules/develop/pages/classes/cells.adoc
decidim-0.29.0.rc3 docs/modules/develop/pages/classes/cells.adoc
decidim-0.29.0.rc2 docs/modules/develop/pages/classes/cells.adoc
decidim-0.29.0.rc1 docs/modules/develop/pages/classes/cells.adoc
decidim-0.28.2 docs/modules/develop/pages/classes/cells.adoc
decidim-0.28.1 docs/modules/develop/pages/classes/cells.adoc
decidim-0.28.0 docs/modules/develop/pages/classes/cells.adoc
decidim-0.28.0.rc5 docs/modules/develop/pages/classes/cells.adoc
decidim-0.28.0.rc4 docs/modules/develop/pages/classes/cells.adoc