GenieFramework / Genie.jl

🧞The highly productive Julia web framework
https://genieframework.com
MIT License
2.25k stars 190 forks source link

Sibling elements not rendered inside @foreach in HTML templates #358

Open tcarion opened 3 years ago

tcarion commented 3 years ago

Describe the bug When several sibling elements are to be rendered inside a @foreach loop, only the last sibling is actually rendered.

Example :

<% @foreach(books) do book %>
    <div>Book name: $(book.name)</div> 
    <div>Book author: $(book.author)</div>
<% end %>

Here only the second div will be rendered.

Expected behavior All the sibling elements should be rendered.

Additional context Julia version:

Julia Version 1.5.3
Commit 788b2c77c1* (2020-11-09 13:37 UTC)
Platform Info:
  OS: Linux (x86_64-redhat-linux)
  CPU: Intel(R) Xeon(R) Gold 6254 CPU @ 3.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, cascadelake)
Environment:
  JULIA_REVISE = auto

Packages:

  [8f4d0f93] Conda v1.5.1
  [b16dfd50] GRIB v0.3.0
  [c43c736e] Genie v1.17.1
  [e115e502] GenieAuthentication v0.7.0 `https://github.com/GenieFramework/GenieAuthentication.jl#master`
  [682c06a0] JSON v0.21.1
  [e6f89c97] LoggingExtras v0.4.6
  [739be429] MbedTLS v1.0.3
  [30363a11] NetCDF v0.11.3
  [438e738f] PyCall v1.92.2
  [295af30f] Revise v3.1.14
  [340e8cb6] SearchLight v0.22.0
  [21a827c4] SearchLightSQLite v0.6.0
  [b3cc710f] StaticLint v7.0.0
essenciary commented 3 years ago

Thanks for raising this issue. Unfortunately this is a complex issue which I haven't been able to solve in a long time. The solution atm is to use a view partial for anything more complex.

Ex:

<ul>
  <% for_each(books) do book %>
    <% partial("app/resources/books/views/_list_item.jl.html", book = book, context = @__MODULE__) %>
  <% end %>
</ul>

The _list_item view partial has:

<li> 1. $(book.title) by $(book.author)</li>
<li> 2. $(book.title) by $(book.author)</li>

And the output: image