検索

HTMX is the successor to intercooler.js, as is used to extend HTML with HTTP commands without needing to write an API. Now, I know in the beginning I said I was removing abstraction layers, however I'm more of systems/tooling programmer, so I still need some abstractions until I have a grasp of what is actually happening underneath.

Basic Concept

HTMX deploys AJAX commands to modify an element. This is similar to how ReactJs works. ReactJs allows for updating content, and HTMX is fulfilling that for HTML.

Import HTMX

A simple one liner is added to ./internal/views/layout.templ

element.

This was already included in the repo, however it has been updated to verify the script.

Using HTMX

HTMX comes with all of your favorite keywords appended with hx-.

# General format is hx-[verb]
hx-get        # HTTP GET
hx-post       # HTTP POST
hx-put        # HTTP PUT
hx-patch      # HTTP PATCH
hx-delete     # HTTP DELETE
hx-swap       # update content of an element
hx-target     # specify element to affect
hx-trigger    # action that executes function

There are more, however these are the main ones used in this project.

For a simple test, in ./internal/views/components/logo.templ, inside of the opening HTMX を GO に追加する tag, we're going to add hx-get="/" and hx-trigger="click".

Open your terminal and run:

templ generate
go run ./cmd/server/main.go

Now go to your browser and go to localhost:[YOUR PORT]/. Click on Gopher, and you should see... well, it happened so fast, you probably didn't notice. That's okay. Open the developer tools, and go to the inspector tab. Click the Gopher again. You should notice the update in the HTML in the inspector tab.

HX-SWAP

This is the bread and butter of HTMX. This is what gives us the responsive UI/UX we're looking for. Now, hx-swap, while simple in name, needs careful consideration on it's location. By this, I mean, do not put it where it will interfere with other elements.
Example:

<div> // container
    <button hx-delete="[endpoint]" hx-target="nearest [element]" hx-swap="outerHTML" hx-get="[endpoint]"> // actor
    </button> // end actor
</div>// end-container

Placing all of the control on the button, will cause everything to be erased and prevent a button, for updating, being displayed. However, if we move some of the work to the container:

<div hx-get="[endpoint]" hx-target="this"> // container
    <li>
        <button hx-delete="[endpoint]" hx-target="nearest [element]" hx-swap="outerHTML"> // actor
        </button> // end actor
    </li>
</div>// end-container

Now, when we click the button, only the data INSIDE of the container is changed, except now a button exists for further editing.

Addendum

I'm stopping here for two (2) reasons.
First, you can use htmx and customize your site with it as it is. Second, we can return html code with a http.Reponse. By extension, we can pass templ components as well. Do you see where this is going?

Coming Soon

An entire restructure and moving functionality into go handlerFunc()s.

Adding HTMX to GO

以上がHTMX を GO に追加するの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
GO BYTEスライス操作を学ぶ:「バイト」パッケージを操作するGO BYTEスライス操作を学ぶ:「バイト」パッケージを操作するMay 16, 2025 am 12:14 AM

byteSpackageIngoisESSENTINEFORMANIPULATINGBYTESSLICEFECTILY.1)useBytes.jointoconcatenateSlices.2)employbytes.bufferfordynamicdataConstruction.3)futilizedexandContainsforsearching.4)applaleplaceandtrimodifications.5)usebydificetes.5)

「エンコーディング/バイナリ」パッケージを使用して、GOのバイナリデータをエンコードおよびデコードする方法(ステップバイステップ)「エンコーディング/バイナリ」パッケージを使用して、GOのバイナリデータをエンコードおよびデコードする方法(ステップバイステップ)May 16, 2025 am 12:14 AM

「エンコード/バイナリ」パッケージを包装して、ボディングを作成しているのを補充します

「エンコード/バイナリ」パッケージを使用して、GOのバイナリデータをエンコードおよびデコードするにはどうすればよいですか?「エンコード/バイナリ」パッケージを使用して、GOのバイナリデータをエンコードおよびデコードするにはどうすればよいですか?May 16, 2025 am 12:13 AM

エンコード/バイナリパッケージは、バイナリデータを処理する統一された方法を提供します。 1)binary.writeとbinary.read関数を使用して、整数や浮動小数点番号などのさまざまなデータ型をエンコードおよびデコードします。 2)カスタムタイプは、Binary.byteorderインターフェイスを実装して処理できます。 3)データの正確性と効率性を確保するために、エンディアンネスの選択、データの調整、エラー処理に注意してください。

Go Stringsパッケージ:それはすべてのユースケースに完全ですか?Go Stringsパッケージ:それはすべてのユースケースに完全ですか?May 16, 2025 am 12:09 AM

Goの文字列パッケージは、すべてのユースケースに適していません。最も一般的な文字列操作では機能しますが、複雑なNLPタスク、正規表現マッチング、および特定の形式の解析にはサードパーティライブラリが必要になる場合があります。

Go Stringパッケージの制限は何ですか?Go Stringパッケージの制限は何ですか?May 16, 2025 am 12:05 AM

Goの文字列パッケージには、多数の文字列操作を処理する際のパフォーマンスとメモリの使用制限があります。 1)パフォーマンスの問題:たとえば、文字列。レプレースと文字列。ReplaceAllは、大規模な文字列置換を扱う場合、効率が低くなります。 2)メモリの使用量:文字列は不変であるため、新しいオブジェクトがすべての操作で生成され、メモリ消費が増加します。 3)Unicode処理:複雑なユニコードルールを処理する場合、柔軟性がなく、他のパッケージやライブラリの助けが必要になる場合があります。

GOの文字列操作:「文字列」パッケージのマスタリングGOの文字列操作:「文字列」パッケージのマスタリングMay 14, 2025 am 12:19 AM

GO言語で文字列パッケージをマスターすると、テキスト処理機能と開発効率が向上します。 1)コンテナ機能を使用してサブストリングを確認し、2)インデックス関数を使用してサブストリング位置を見つけ、3)関数を効率的にスプライスストリングスライス、4)機能を置き換えてサブストリングを置き換えます。空の文字列や大きな文字列操作のパフォーマンスの問題をチェックしないなど、一般的なエラーを避けるように注意してください。

「文字列」パッケージのヒントとトリックに移動します「文字列」パッケージのヒントとトリックに移動しますMay 14, 2025 am 12:18 AM

文字列の操作を簡素化し、コードをより明確かつ効率的にすることができるため、GOの文字列パッケージを気にする必要があります。 1)文字列を使用して、弦を効率的にスプライスするために参加します。 2)文字列を使用して、空白の文字で文字列を分割します。 3)文字列を介してサブストリング位置を見つけます。Indexと文字列lastindex; 4)文字列を使用して、文字列を置き換える。 5)文字列を使用して、ビルダーを効率的にスプライスします。 6)予期しない結果を避けるために、常に入力を確認してください。

Goの「文字列」パッケージ:文字列操作のためのあなたの頼みGoの「文字列」パッケージ:文字列操作のためのあなたの頼みMay 14, 2025 am 12:17 AM

theStringspackageIngoisESSENTINEFOREFFSTRINGMANIPULATION.1)ITOFFERSSSIMPLEYETPOWERFULFUNCTIONS FORTOSSCHECKINGSUBSTRINGSNINGSTRINGS.2)ITHANDLESUNICODEWELL、ITHANDLESUNICODEWELL

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。