jmurphyweb
Given that View modules contain formatting logic, what do you do if you want to format some data in your main application (ie in lib/myapp/ as opposed to in the lib/myapp_web/) ?
We are doing a load of CSV exports, and I keep finding myself aliasing View modules in my library modules which feels dirty.
How do you handle this? Do you have any self-enforced rules about which modules can call others? I’d love to hear about them!
Trending in Discussions
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
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
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
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
Hi there! :wave:
@frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
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
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
First I’d ask: why do you use Views for CSV output?
You can just use
nimble_csvin your controller and directly return the CSV withrender text: csv_outputor some such (sorry, forgot the actual Phoenix syntax).jmurphyweb
Thanks for the reply @dimitarvp
I am using view logic to format the data in the same way as we do in our templates.
Here is a trivial example:
This is a really basic example of pseudo code but it is exactly the issue that I am facing in many places in my application. In reality, there is too much formatting to just redefine the functions locally to this module.
Any help really appreciated
dimitarvp
What do you mean by that? CSV doesn’t need formatting.
jmurphyweb
There are too many of these “formatting” functions:
UserView.format_address(user)dimitarvp
So am I understanding correctly: you don’t want to use
nimble_csvand you want to keep using Phoenix Views for CSV formatting because the functions that output the proper CSV fields are too many?jmurphyweb
Hi @dimitarvp. No you aren’t understanding me correctly.
I am happily using NimbleCSV. Maybe forget that I ever mentioned CSV
I think this is the crux of my question:
I feel like it is not good design/practice to reference my
UserViewmodule in myAccounts.Users.ExportCSVmodule and wanted to understand how people would get around this issue.lud
They just want access for example the
full_name(user)function defined in the view to fill the CSV columnfull_namein the CSV generating code.@ jmurphyweb you could move your helpers in the data model and import them from your view and your csv code.
dimitarvp
Oops, sorry for the derp.
In all Phoenix projects where I had any influence, I always moved such functions outside the
_webnamespace. They absolutely don’t belong there in my eyes. They are also not views per se, they are like data reshapers / transformers / whatever-you-want-to-call them.So yep, move them to the other namespace and don’t have a care in the world.
mindok
I think this would be better reworded as “Given that View modules contain formatting code specifically for rendering one or more web-pages”. Then there would be no confusion. If it isn’t to do with a web page or API output, it doesn’t belong in the _web part of the project.
It is dirty, that’s why it feels dirty!
jmurphyweb
That’s honestly really eye opening for me. I thought this basic formatting was exactly the purpose of View modules in Phoenix!
It sounds like you are saying the View modules are specifically for putting controller/context provided data into a shape that a template will readily consume. Is that pretty much it?
Can I just double check my comprehension:
Create these data formatters somewhere in/round the User module and then alias that module in my view module for access by the templates?
I can see why that is an improvement, but something still seems a little off the me