Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

Passing data to our templates

One thing we will frequently want to do is pass some data along our controller down to the templates that are doing the display work, especially if there is any sort of conditional display logic or anything like that. If we run h Phoenix.Controller.render in our IEx terminal, we’ll see a definition for the function that matches the following:

def render(conn, template, assigns)

Right now, we’re passing along conn and index.html (remember that anything using the pipeline operator |> passes the result as the first argument into the next function), so let's also pass along some assigns. Specifically, we'll pass along a dummy data structure for our first poll. Open up poll_controller.ex and let's change the index ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content