Amu
Hi. I am developing single page blog website, using LiveView.
I want to render html template according to URL path .
For example
blog directory has many html files as “blog posts” like as below
blog/post-1.html.heex
blog/post-2.html.heex
.
.
.
blog/post-100.html.heex
If I access http://localhost:4000/blog/post-1
I want to get post-1.html as LiveView.
Perhaps I need to set route, but I am not sure.
live “/blog/:post”, BlogLive.Index, :index
And I need to use ‘embed_templates’ perhaps.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
ollien
Before I answer your question: I just want to ask if using a LiveView and a functional component is the most appropriate tool for this? You would be better served with these files being rendered to disk as plain HTML (or some other templating language, like Mustache), and serving those files directly (or applying your templating function of choice). See this post for some more details: How can one render a Liveview .heex file dynamically? - #2 by benwilson512
However, if you truly understand what you are doing (or just want to learn
), you can do what you want using
Kernel.apply/3. Again, I would not suggest this; you’re effectively allowing a requester to select a function for them to execute. Further, HEEx templates are arbitrarily powerful, and a setup like this could be used for arbitrary code execution on your server, given the right circumstances.To set this up in the safest way possible (again, I would not consider this really that safe), I split out the components into a separate
PageHTMLmodule. Here’s the associated directory structure.PageHTMLis quite simple in that it just usesembed_templates, as you suggestI defined a route for the live view as
…which renders the following live view
Now, when someone navigates to
/page-1, thepage-1template will be renderedand when visiting a template that doesn’t exist, they will get “Not found”
Hope this helps! Now, don’t do this
Amu
Thank you very much ollien !!
I understand you do not recommend using LiveView for this purpose.
Again, Could you tell me how to render static HTML file accoring to URL PATH without using LiveView.
ollien
You can either serve it as a static file directly (perhaps my suggested approach if just using plain
.htmlfiles). This page, though not a direct tutorial, should get you started. Asset Management — Phoenix v1.8.8You can also use an approach like this to render a string as your controller response, which would be particularly useful if you are using templates https://stackoverflow.com/a/67350254
Amu
you help me a lot !