Render several fragments of a view at once (fragments, fragmentsIf)

Open
#862 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

Start by reading the View::fragment and Template::block() APIs and how the engine consumes them; the issue names no source files or tests. Trace how fragment selection reaches an engine, then determine how ordered multiple fragments should be passed through and rendered. Done means fragments and fragments_if support multiple names while preserving single-fragment behavior and rendering in order.

Written by the indexing model from the issue text.

Description

Laravel's fragments(['a', 'b']) and fragmentsIf(...) render several fragments of one view in order, which htmx-style responses use to update more than one region at once. Laravel for Rust 0.2 has View::fragment and fragment_if for one fragment only.

use laravel::view::view;

let page = view("two", ()).fragment("a").fragment("b");
// The second call replaces the first: only "b" renders.

let page = view("two", ()).fragments(["a", "b"]);
// error[E0599]: no method named `fragments` found for struct `View`

View::fragment stores self.block = Some(..), and an Engine reads it through Template::block() -> Option<&str>, so a third-party engine can't receive more than one name either.

A possible shape: View::fragments(names) and fragments_if(condition, names), and Template::blocks() -> &[String] (keeping block() for a single fragment), with engines concatenating the fragments in the order given, as Laravel does.

Context: this came up while porting Blade to Laravel for Rust as a view engine (oxblade); it supports multiple fragments in its own API but can't receive them from View.

Dominant language
Rust
Stars
847
Forks
174
Avg merge
5h 40m
Merged PRs (30d)
167

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from laravel/rust-framework

All issues in laravel/rust-framework

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.