【发布时间】:2022-01-03 21:34:05
【问题描述】:
我有以下路线和控制器动作。
scope "/", StarTrackerWeb do
pipe_through(:browser)
get("/", PageController, :index)
get("/info/", PageController, :about)
get("/info/:name", PageController, :about)
get("/info/:name/:position", PageController, :about)
end
def about(conn, params) do
names = ["Jose", "Chris", "Jeffrey"]
render(
conn,
"information.html",
name: params["name"],
position: params["position"],
names: names
)
end
目标是在我的模板中的此链接帮助程序中插入 @position 分配。
<%= for name <- @names do %>
<li><%= link "#{name} the ", to: Routes.page_path(@conn, :about) %></li>
<% end %>
</ul>
所以,给定 URL“/info/jose/engineer”。
生成的链接文本应该是:
何塞工程师
但是,直接调用分配或插入它们都不起作用。
<%= link "#{name} the @position ", to: Routes.page_path(@conn, :about) %></li>
<%= link "#{name} the #{position} ", to: Routes.page_path(@conn, :about) %></li>
【问题讨论】:
标签: html elixir phoenix-framework