Using plugs to synchronize child and parent templates

Hello! I have been trying to follow stackoverflow to sync elements in two different templates. I came up with the code below as part of this, but get the following compiler error:

== Compilation error on file lib/plugs.ex ==
** (CompileError) lib/plugs.ex:8: undefined function assign/3

Here is the code:

defmodule LookupPhoenix.Plug.Site do

  def init(default), do: default

  def call(conn, opts) do
    assign conn, :site,  Keyword.get(opts, :site)
  end

end

And here is how I call it:

plug LookupPhoenix.Plug.Site, site: site

Advice?

1 Like

You are not importing assign, just need to import the correct module that defines it (Plug.Conn maybe). :slight_smile:

1 Like

It compiles now!

2 Likes