Comments (3)
Hello @sitch.
Thanks for opening an issue!
Would you mind sharing more details about your use-case? I'm struggling to see where this would be more powerful than a simple string interpolation?
Thanks!
from phoenix_swoosh.
Well firstly, rendering the subject as a template can be useful non-devs to maintain the templates. My use case is more that i am passing an assigns
map to render_body/3
or to Swoosh.Email.new/1
, and I can just repeat myself or i can access those assigns variables for consistency
from phoenix_swoosh.
This is what i'm using internally to do:
new()
|> assign(:name, "Sitch")
|> render_subject(~S("Welcome #{name}"))
|> render_body("template.html")
defmodule RenderingSubject do
def render_subject(%Swoosh.Email{assigns: assigns} = struct, template) do
subject = eval_quoted_string(template, assigns)
%{struct | subject: subject}
end
def eval_quoted_string(template, assigns) when is_binary(template) and is_map(assigns) do
with assignment_list <- Enum.into(assigns, []),
{result, _assign} <- Code.eval_string(template, assignment_list)
do
result
else
_ -> raise "Unknown argument in .eval_quoted_string/2"
end
end
end
from phoenix_swoosh.
Related Issues (17)
- Error when following User_Email example HOT 1
- Release a version based on phoenix 1.3.0-rc HOT 2
- respect the bang syntax HOT 1
- Not yet published? HOT 2
- Mismatch of File doc and Hexdoc HOT 1
- A heads up: we have extract phoenix_view into a separate project HOT 2
- would it be possible to do another release ? HOT 4
- phoenix 1.6-rc0 - render_body with atom do nothing HOT 13
- Upgrading to Swoosh 0.13 HOT 2
- How is the struct %Email{} available? HOT 3
- Phoenix 1.7 and phasing out Phoenix.View HOT 24
- ArgumentError: 1st argument: not an iodata term HOT 6
- phoenix_html 4.0 compatibility HOT 2
- render_body exception when using email as an assign. HOT 1
- Incorrect Swoosh.Email struct keys set HOT 5
- Why does it need to be in application HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phoenix_swoosh.