thanos
Environment
Erlang/OTP 21 [erts-10.2.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace]
IEx 1.8.1 (compiled with Erlang/OTP 21)
{:phoenix, "~> 1.4.2"},
{:phoenix_html, "~> 2.11"},
The Problem
I’m trying to use Vue templates in a Phoenix template.
Given this
<template>
<a href="job/{{ job.id }}">{{ job.name }}</a></div>
</template>
So instead of
/job/1234
We get this
/job/%7B%7B%20job.id%20%7D%7D
Trying
<a href='<%= raw "{{ job.id }}" %>'>{{ job.name }}</a>
and another other ideas from Phoenix.Template.HTML does not solve the problem.
In other systems such Django I can do things like
{% verbatim %}
<a href="{{ job.id }}">{{ job.name }}</a>
{% endverbatim %}
I understand Phoenix template is a different beast but there must be a way…
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
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
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
In Phoenix template, that should be
But I have never used Vue.
peerreynders
Aside:
The
templatetag is part of Vue’s SFC spec and is expected to be in a.vuefile which is an asset intended to be compiled before deployment by the front end build system (the Vue compiler turns it into pure JavaScript).Any
templatetag rendered by EEx and served by Phoenix is going to be interpreted by the browser as a native contenttemplateelement which is an entirely different beast.Even if Vue can use the template content client side - you should aim to avoid any approach that requires that you use the Full build:
thanos
That might be so but my issue is neither how I’m using Vue nor my FCP and TTI requirements but something more simple: How can I emulate
I just used the above as an example.
Anyways thanks @peerreynders for your answer.
thanos
thanks @Kokolegorille, using an elixir comment - nice !
peerreynders
string interpolation actually.
String.Charsprotocol.thanos
Quite right thanks for the correction but out of desperation I also tried to use a comment to avoid evaluation but without success.
peerreynders
One of the issues is that in fact you aren’t trying this at all:
That case is covered by
Phoenix.HTML.raw/1.This makes it sound like you want to supply
job.idfrom Elixir on the server side - but the mustache syntax suggests thatjob.id(andjob.name) are supposed to be handled client-side by Vue.Which begs the question - is
job.id(andjob.name) a server side Elixir value (to be handled by EEx/Phoenix) or a client-side JavaScript value (to be handled by Vue/browser)?In a vanilla Phoenix app in
index.html.eexI inserted both:and
and they rendered in the browser as expected verbatim - there is no collision.
Possibly the missing piece of the puzzle? Django template variables use the mustache syntax.
The EEx template tags are documented here.
If on the other hand you are trying to bind a client side value then maybe you need this:
jeremyjh
Phoenix templates use eex by default. Interpolation is done like this:
This assumes you passed an assign called
jobto the template alarender(conn, :show, job: job)thanos
@peerreynders I’ve gone through the same process and arrived at the same point as you but I was offline for a while and didn’t see your subsequent post.
Many thanks for your help.
Thanks to this problem and everybody’s help I have a much better understanding of the
Phoenix.Template.EExEnginewhich very different (and cool ) from others I’ve used.Many thanks to all.
peerreynders
One reason why I brought up those issues is that Vue.js is typically used to build an SPA.
In that case it is common to serve the SPA completely decoupled from Phoenix - which also leaves the option open to use Nuxt.js for SSR to pre-render Vue.js to improve client-side performance. Phoenix then acts simply as a JSON or GraqhQL server (with Absinthe) for the SPA.
Going down the Vue.js SPA road there really isn’t any use for EEx templating. EEx is more useful for building dynamic web pages. Now it is conceivable to use dynamic pages that include a component that uses Vue.js but that use case doesn’t seem to be all that common.