You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you'd like to discuss your feature idea first with the community (highly recommended!) please visit our Discord channel.
Is your feature request related to a problem? Please describe.
Right now, the default title for all (non-htmx) routes is "FastHTML page". I think it would be useful to be able to set a default title that is relevant to one's own project. This would guarantee that a non-sequitur title would not appear if one neglected to add a title to a given route, and would save a little boilerplate for routes where a custom title isn't warranted.
This question has previously been raised here: #208
JPH notes that the standard pattern is to set a title per route, and notes that "it would be a bit tricky to support having titles defined in headers too." Both those points make sense, and JPH is of course best-positioned to make judgments about the difficulty of supporting features.
Describe the solution you'd like
There might be a fast_app(..., title="my site", ...) or fast_app(..., default_title="my site", ...) that effectively replaces the default "FastHTML page" with "my site".
Or the pattern might be to allow the definition of a Title() in the hdrs= argument to fast_app(). (This is allowed now, it just doesn't have the intended effect because the headers defined via hdrs= appear after the default title.)
Example code
For the moment, I have been implementing a default title using Beforeware, as follows:
This way any included Title() in fast_app(hdrs=...) would precede those in titles, and be shown in the browser.
Alternative 3
A .default_title attribute defined via fast_app(), a la def fast_app(..., default_title: str="FastHTML page", ...): ... could be added to the req object, so the line in fasthtml.core:_xt_cts():
if not titles: titles = [Title('FastHTML page')]
might become:
if not titles: titles = [Title(req.default_title)]
Similar implementations
N/A
Problem solved
Mentioned above. Avoids non sequitur titles, minor arguable boilerplate reduction.
Additional context
None.
Confirmation
Please confirm the following:
I have checked the existing issues and pull requests to ensure this feature hasn't been requested before.
I have read the project's documentation to ensure this feature doesn't already exist.
The text was updated successfully, but these errors were encountered:
If you'd like to discuss your feature idea first with the community (highly recommended!) please visit our Discord channel.
Is your feature request related to a problem? Please describe.
Right now, the default title for all (non-htmx) routes is "FastHTML page". I think it would be useful to be able to set a default title that is relevant to one's own project. This would guarantee that a non-sequitur title would not appear if one neglected to add a title to a given route, and would save a little boilerplate for routes where a custom title isn't warranted.
This question has previously been raised here: #208
JPH notes that the standard pattern is to set a title per route, and notes that "it would be a bit tricky to support having titles defined in headers too." Both those points make sense, and JPH is of course best-positioned to make judgments about the difficulty of supporting features.
Describe the solution you'd like
There might be a
fast_app(..., title="my site", ...)
orfast_app(..., default_title="my site", ...)
that effectively replaces the default "FastHTML page" with "my site".Or the pattern might be to allow the definition of a
Title()
in thehdrs=
argument tofast_app()
. (This is allowed now, it just doesn't have the intended effect because the headers defined viahdrs=
appear after the default title.)Example code
For the moment, I have been implementing a default title using Beforeware, as follows:
(The code where the contents of
req.injects
gets converted into headers is here, i.e. infasthtml.core:_xt_cts()
.)This same mechanism might be used, i.e. adding a
default_title=
value toreq.injects
.Alternative 2
Another way might be to, in
fasthtml.core:_xt_cts()
, flip the order oftitles
andreq.hdrs
from:resp = Html(Head(*titles, *flat_xt(req.hdrs)), ...)
to
resp = Html(Head(*flat_xt(req.hdrs)), *titles, ...)
This way any included Title() in
fast_app(hdrs=...)
would precede those intitles
, and be shown in the browser.Alternative 3
A
.default_title
attribute defined viafast_app()
, a ladef fast_app(..., default_title: str="FastHTML page", ...): ...
could be added to thereq
object, so the line infasthtml.core:_xt_cts()
:if not titles: titles = [Title('FastHTML page')]
might become:
if not titles: titles = [Title(req.default_title)]
Similar implementations
N/A
Problem solved
Mentioned above. Avoids non sequitur titles, minor arguable boilerplate reduction.
Additional context
None.
Confirmation
Please confirm the following:
The text was updated successfully, but these errors were encountered: