fsa

fsa

Just a quick note - have you tried the following:

<div>
<%= case @nav do %>
<% :post -> %>
  <%="<div>Post view goes here</div>" %>

<% :main -> %>
  <%="<div>Main view goes here</div>" %>

<% :board -> %>
  <%="<div>Board view goes here</div>" %>

<% end %>
</div>

I have done some eex for JSON, html etc… and a quick look made me think this might nudge you in the right direction…

p.s.
It has been a while since I was doing it, and it was on elixir 1.9 just in case if that matters
R.
Fridrik.

0
Post #11
benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

This will not work the way you want it to, it will escape the inner HTML. <%= "<div></div>" %> shouldn’t be necessary, it should be possible to just <div></div>. I think @tschnibo is on to something, my guess is that @APB9785’s code is doing do%>

0
Post #12
APB9785

APB9785 OP

Creator of ECSx

Sure! Here’s a link to the page_live.html.leex I’m running when I get the error:

The full error for this file is

== Compilation error in file lib/phx_bb_web/live/page_live.ex ==
** (SyntaxError) lib/phx_bb_web/live/page_live.html.leex:11: unexpected operator ->. If you want to define multiple clauses, the first expression must use ->. Syntax error before: '->'
    (eex 1.11.3) lib/eex/compiler.ex:126: EEx.Compiler.generate_buffer/4
    (eex 1.11.3) lib/eex/compiler.ex:65: EEx.Compiler.generate_buffer/4
    (phoenix_live_view 0.15.4) expanding macro: Phoenix.LiveView.Renderer.__before_compile__/1
    lib/phx_bb_web/live/page_live.ex:1: PhxBbWeb.PageLive (module)
    (elixir 1.11.3) lib/kernel/parallel_compiler.ex:314: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7
0
Post #13
patrickdm

patrickdm

Just a guess but… did you try without this html comment?

6
Post #14
APB9785

APB9785 OP

Creator of ECSx

You know, I thought I had tried that already, but I guess not, because you’re totally right. The case statement must expect the first pattern to come immediately, and the comment beforehand was breaking syntax.

In the previous version, I was using nested if-else statements for this navigation switch, and the comments weren’t bothering anything. But now I see that in a case statement, the comments must come AFTER the pattern clause to match.

Thanks so much for taking the time to help!

3
Post #15
the_wildgoose

the_wildgoose

Totally unrelated to your question, but…

…Try “Surface”! It changed my life! :smile:

You can take each of those big groups of HTML, slap them in a “component” and then you insert something like a “fake html” tag into the code. The tag gets inflated into the contents of the component.

Now at this point you are correct in pointing out this is no different to using a partial. However, the syntax is similar to adding new HTML tags, so this also implies that the content of the tag gets passed in kind of like a param into the partial function.

I use it by creating a component say “BoilerPlate”, which is the outline of the form, it only contains components like “SideBar”, “TopNav” and “Content”. These inflate to their own components and so on. Content will be the wrapped content, which in your case will be one of several components, decided by the results of the case statement.

I’m then creating a folder with the same name as the component and further break that main content down into a small enough number of pieces that it’s understandable. I really like it!

2
Post #16
— All posts loaded —