Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Masatoshi Nishiguchi
Masatoshi Nishiguchi

Posted on • Edited on

     

Phoenix 1.6 Page Title

I made a customawesome_title_tag view helper function because I wanted to support both controller views and live views.

View

Inlib/mnishiguchi_web/views/layout_view.ex

defmoduleMnishiguchiWeb.LayoutViewdouseMnishiguchiWeb,:view@site_name"Mnishiguchi"defsite_name(),do:@site_namedefawesome_title_tag(conn,assigns)dolive_title_tag(page_title(conn,assigns)||@site_name,suffix:" ·#{@site_name}")end# live viewdefppage_title(_conn,%{page_title:page_title}=_assigns)dopage_titleend# controller viewdefppage_title(conn,assigns)doiffunction_exported?(view_module(conn),:page_title,2)doview_module(conn).page_title(view_template(conn),assigns)else@site_nameendendend
Enter fullscreen modeExit fullscreen mode

Template

In/lib/mnishiguchi_web/templates/layout/root.html.leex

   <meta http-equiv="X-UA-Compatible" content="IE=edge"/>   <meta name="viewport" content="width=device-width, initial-scale=1.0"/>   <%= csrf_meta_tag() %>-  <%= live_title_tag assigns[:page_title] || "Home", suffix: " · Masatoshi Nishiguchi" %>+  <%= awesome_title_tag(@conn, assigns) %>
Enter fullscreen modeExit fullscreen mode

Resources

Because of breaking changes between Phoenix 1.4 and 1.5, many examples out there did not work with Phoenix 1.5.

Here are some resources I referenced:

That's it.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

たのしむ
  • Location
    🇯🇵
  • Work
    ソフトウエアエンジニア
  • Joined

More fromMasatoshi Nishiguchi

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp