Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
名古屋商科大学ビジネススクール様 事例紹介
Search
笠谷@アップルップル
September 17, 2024
Technology
0
48
名古屋商科大学ビジネススクール様 事例紹介
a-blog cms で構築された既存のサイトに htmx を取り入れる
笠谷@アップルップル
September 17, 2024
Tweet
Share
Other Decks in Technology
See All in Technology
オブザーバビリティと育てた ID管理・認証認可基盤の歩み / The Journey of an ID Management, Authentication, and Authorization Platform Nurtured with Observability
kaminashi
1
690
現場の壁を乗り越えて、 「計装注入」が拓く オブザーバビリティ / Beyond the Field Barriers: Instrumentation Injection and the Future of Observability
aoto
PRO
1
590
OTEPsで知るOpenTelemetryの未来 / Observability Conference Tokyo 2025
arthur1
0
240
Dify on AWS 環境構築手順
yosse95ai
0
130
個人でデジタル庁の デザインシステムをVue.jsで 作っている話
nishiharatsubasa
3
5.1k
アウトプットから始めるOSSコントリビューション 〜eslint-plugin-vueの場合〜 #vuefes
bengo4com
3
1.8k
AIとともに歩んでいくデザイナーの役割の変化
lycorptech_jp
PRO
0
880
20251027_findyさん_音声エージェントLT
almondo_event
2
430
AWS DMS で SQL Server を移行してみた/aws-dms-sql-server-migration
emiki
0
230
Okta Identity Governanceで実現する最小権限の原則 / Implementing the Principle of Least Privilege with Okta Identity Governance
tatsumin39
0
170
ヘンリー会社紹介資料(エンジニア向け) / company deck for engineer
henryofficial
0
380
頭部ふわふわ浄酔器
uyupun
0
110
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
140
7.2k
Keith and Marios Guide to Fast Websites
keithpitt
411
23k
Typedesign – Prime Four
hannesfritz
42
2.8k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Bash Introduction
62gerente
615
210k
Git: the NoSQL Database
bkeepers
PRO
431
66k
The Straight Up "How To Draw Better" Workshop
denniskardys
238
140k
A Modern Web Designer's Workflow
chriscoyier
697
190k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.2k
Stop Working from a Prison Cell
hatefulcrawdad
272
21k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
54k
jQuery: Nuts, Bolts and Bling
dougneiner
65
7.9k
Transcript
名古屋商科大学ビジネススクール様 事例紹介 a-blog cms で構築された既存のサイトに htmx を取り入れる 2024-9-17 a-blog cms
LIVE vol.19 笠谷亜貴子 @ appleple
今日のセッションの内容 • 実際のサイト https://mba.nucba.ac.jp/ で部分更新 の挙動を紹介、確認 • htmxとは何か — ポストインクルードとの違い
• a-blog cms の各バージョンでの取り入れ方の注意点 • 実装のポイントとコードの紹介
実際のサイトで部分更新の挙動を紹介、確認 • エントリーからエントリーへの遷移でメインコンテンツ部分を 更新 • 一部モジュールユニットではモーダルを使用
htmxとは何か — ポストインクルードとの違い • htmxは hx-get, hx-swap, hx-target などの属性を追加 •
ポストインクルードは js-post_include というクラスを追加 • htmxは2箇所以上を swap できる • htmxは hx-push-url でURLを変更することができる
headタグ内 <script src="https://unpkg.com/
[email protected]
"></script> <script src="https://unpkg.com/htmx.org/dist/ext/ajax-header.js"> </script> 1. 2. • 1行目はhtmxを使用する際は共通で必要
• 2行目は a-blog cms をバックエンドとして使用する際に必 要(Ver. 3.1.17以上であれば不要)
対象要素 hx-ext="ajax-header" • 他の hx-* 属性に上記を追加する(Ver. 3.1.17以上であれ ば不要)
/private/config.system.yaml allow_tpl_path : [template-name.html ] • ポストインクルードでも必要だった設定(Ver. 3.1.17以上で あれば不要)
サイト全体をできるだけエントリーで作る • _top.html や index.html を極力使わないで _entry.html で作る • ブログトップやカテゴリーインデックスでエントリー一覧が必要な場合
はモジュールユニットを使用する • コンタクトフォームなどもエントリーで作ることも可能 • 読み込み先テンプレートを Entry_Body モジュールで共通化
通常の遷移とhtmxでの部分更新の分岐が必要 • エントリーサマリーを使っているモジュールユニットは遷移先が必ずエ ントリー • ナビゲーションモジュールやリストモジュールなどは URL の欄にエン トリー以外のページや外部サイトが含まれる •
htmxでの部分更新の場合はテンプレートor 管理画面の入力時にクエ リとして ?htmx=true を持たせる
aタグのhref属性とhx-*属性をincludeで共通化する href="{{href}}" <!-- BEGIN_IF [{{href}}/lk/?htmx=true/_and_/%{IS_ADMIN}/eq/0] --> hx-get="{{url}}<!-- BEGIN_IF [{{url}}/nre/.*/$] -->/<!--
END_IF -->tpl/include/htmx/entry/body.html" hx-push-url="{{url}}" hx-swap="innerHTML" hx-target="#main-content" hx-trigger="click"<!-- END_IF --> themes/theme_name/include/htmx/attributes-main-content.txt
aタグのインクルード元の書き方(エントリーサマリー) <a @include("/include/htmx/attributes-main-content.txt", { "href":"{url}?htmx=true", "url":"{url}" }) class="...">
aタグのインクルード元の書き方(ナビゲーションモジュールなど) <a @include("/include/htmx/attributes-main-content.txt", { "href":"{url}", "url":"{url}[rmHxQuery]" }) class="...">
swapしたあとの処理 addEventListener ('htmx:afterSwap' , function (evt) { // 部分更新した箇所に acms.jsを再度走らせる
ACMS.Dispatch(evt.target); // main-content の場合 if(evt.target.id === "main-content" ){ window.scrollTo({top: 0, behavior: 'smooth'}); } });
モーダルのテンプレート • #modal-on-movieに表示する際にはbody-content-only.htmlをインク ルードしたテンプレートを読み込み、非表示の際にはdelete.htmlというテンプ レートを読み込んでいる • フェードイン、フェードアウトのアニメーションの始まるタイミングはJS側で制御して いる • .modal-bg
には hx-trigger="click delay:0.8s" .modal-close-button には hx-trigger="click consume delay:0.8s" を設定してあり、アニメー ションが終わってからテンプレートをdelete.htmlに切り替えるようにしてある • JSで hx-*属性を変更したあとには htmx.process(document.body); が必 要 • hx-push-url を使う場合はブラウザのバックボタンとの整合性に注意が必要
まとめ a-blog cms × htmx では、今日ご紹介したコンテンツの部分更新以外にもさ まざまなカスタマイズができそうです。 ぜひいろいろなカスタマイズを試してみてください。
a-blog cms とhtmx でインタラクティブなWebサイトを簡単に構築: https://www.a-blogcms.jp/htmx/ 開発ブログ: https://developer.a-blogcms.jp/blog/htmx/ ハンズオン用環境: https://www.ablogcms.io/htmx/?theme=workshop@blog#form 次回のhtmx勉強会
10/2(水)20:00 - https://ablogcms-online.doorkeeper.jp/events/177635