Sitesx v0.11.0 Sitesx.Helpers View Source

Generate URL with subdomain for controller or templates along with Phoenix.HTML.SimplifiedHelpers.URL

Import module

# web/web.ex
defmodule MyApp.Web do
  def view do
    quote do
      use Phoenix.View, root: "web/templates"
      ...
      ...
      ...
      import Sitesx.Helpers
    end
  end
end

Example

subdomain_url(@conn, "entry.latest")
#-> http://subdomain1.example.com/entries/latest

subdomain_url("www", @conn, "page.index")
#-> http://www.example.com/entries/latest

A conn variable contains sitesx struct(model) which has domain information through a Sitesx.Plug module that extracted from request URL or sub queryparameter.

Link to this section Summary

Functions

Generate URL from Plug.Conn struct or subdomain name

Generate URL with querystring from subdomain name

Link to this section Functions

Link to this function subdomain_url(conn, ctrl_act_param, opts \\ []) View Source
subdomain_url(conn :: Plug.Conn.t, ctrl_act_param :: String.t, opts :: list) :: String.t
subdomain_url(subdomain :: String.t, conn :: Plug.Conn.t, ctrl_act_param :: String.t) :: String.t

Generate URL from Plug.Conn struct or subdomain name

Call function with ensured DNS record.
subdomain_url(@conn, "entry.latest")
#-> http://subdomain1.example.com/entries/latest
Call function with not ensured DNS record.
subdomain_url(@conn, "entry.latest")
#-> http://example.com/entries/latest?sub=subdomain1
Call function with ensured DNS record.
subdomain_url("subdomain2", @conn, "entry.latest")
#-> http://subdomain2.example.com/entries/latest
Call function with not ensured DNS record.
subdomain_url("subdomain2", @conn, "entry.latest")
#-> http://example.com/entries/latest?sub=subdomain2
Link to this function subdomain_url(subdomain, conn, ctrl_act_param, opts) View Source
subdomain_url(subdomain :: String.t, conn :: Plug.Conn.t, ctrl_act_param :: String.t, opts :: list) :: String.t

Generate URL with querystring from subdomain name

Call function with ensured DNS record.
subdomain_url("subdomain2", @conn, "entry.latest", some: "query", unko: "query2")
#-> http://subdomain2.example.com/entries/latest?some=query&unko=query2
Call function with not ensured DNS record.
subdomain_url("subdomain2", @conn, "entry.latest", some: "query", unko: "query2")
#-> http://example.com/entries/latest?sub=subdomain2&some=query&unko=query2