Atypical.MinimalHtmx.Templates
1.0.0
dotnet new install Atypical.MinimalHtmx.Templates::1.0.0
MinimalHtmx Template đĻđ
A minimal .NET template for creating HTMX-based Blazor projects, leveraging Carter for routing and component-based architectures. This template provides a foundation for building interactive, server-driven web applications with Blazor and HTMX.
Table of Contents đ
Overview đ
This template includes:
- 2 Blazor components (
PageCounter
andPageContact
) with HTMX integration for building dynamic, server-side pages. - Carter-based routing to handle minimal APIs seamlessly.
- Pre-configured HTMX components (
HxCounter
,HxContact
andHxContactEdit
) to handle server-side rendering and interactivity. - A clean, minimal structure that supports server-side HTML updates without JavaScript.
Features â¨
- HTMX Integration: Use HTMX to enable dynamic HTML updates without JavaScript, leveraging server-side interactions.
- Carter Routing: Minimal API routing using Carter makes defining API routes simple and clean.
- Blazor Components: Blazor components are used to encapsulate the UI, supporting easy reuse and testing.
- .NET 8 Support: Built to target .NET 8.0, ensuring compatibility with the latest features and enhancements.
- Form Handling: Use
hx-put
andhx-get
to enable form binding and server-side state management.
Installation âī¸
Install the template using the dotnet new
command:
dotnet new install Atypical.MinimalHtmx.Templates
Usage đ
Create a new project using the template:
dotnet new minimalhtmx -n YourProjectName
This command creates a new directory named YourProjectName
with the template contents.
Running the Project âļī¸
Once the project is created, navigate to the directory and run the application:
cd YourProjectName
dotnet run
The project will be available at https://localhost:{PORT}
by default.
Project Structure đī¸
Pages/Counter/PageCounter.razor
: Main Blazor component to display a counter.Pages/Counter/PageCounter.razor.cs
: Defines API endpoints using Carter to handle GET and POST requests for counter data.Pages/Counter/HxCounter.razor
: HTMX-enabled component that displays a counter.Pages/Contact/PageContact.razor
: Main Blazor component to display a contact.Pages/Contact/PageContact.razor.cs
: Defines API endpoints using Carter to handle GET and PUT requests for contact data.Pages/Contact/HxContact.razor
: HTMX-enabled component that displays a contact's details.Pages/Contact/HxContactEdit.razor
: HTMX-enabled edit form for contacts.Store/AppState.cs
: Stores the state of the application, including contact details.
Customization âī¸
Adding New Routes â
To add new routes, modify the AddRoutes
method in PageContact.cs
. You can define new GET, POST, PUT, or DELETE endpoints using Carter's fluent routing API.
public void AddRoutes(IEndpointRouteBuilder app)
{
var group = app.MapGroup("htmx/contact");
group.MapGet("/{Id:int}", HandleGet);
group.MapPut("/{Id:int}", HandlePut);
group.MapPost("/new", HandleCreateNew);
}
Modifying Components đ ī¸
Components are located by feature in the Pages
folder. You can edit HxContact.razor
and HxContactEdit.razor
to change the UI and behavior of the contact display and edit functionality.
Using AppState đž
AppState.cs
is used to store the state of your application, such as contact details. You can extend AppState
to hold more data as your application grows.
Contributing đ¤
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request to the repository.
License đ
This project is licensed under the MIT License. See the LICENSE file for details.
About âšī¸
Developed by Philippe Matray, this template is aimed at developers looking for a minimal yet effective way to combine Blazor with HTMX and Carter, enabling interactive, server-driven web applications without relying on complex JavaScript frameworks.
Quick Start Guide đ
Install the Template
dotnet new install Atypical.MinimalHtmx.Templates
Create a New Solution
mkdir HtmxDemo cd HtmxDemo dotnet new sln -n MyHtmxSolution
Create a New MinimalHtmx Project
dotnet new minimalhtmx -n MyHtmxApp dotnet sln add MyHtmxApp
Run the Application âļī¸
Navigate to the project folder and run it:
cd MyHtmxApp dotnet run
You should see the application running at
https://localhost:{PORT}
.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 97 | 11/6/2024 |