-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Loops for templating #251
Comments
What I'm thinking, is that it might be easier to use Julia to do this. mutable struct person
name
image
description
end
peopleNumber = 2; # Change this if number of people changes
people = Array{person}(undef, peopleNumber)
# Change this by inserting name, image name, and description
people[1] = person("John", "John.jpg", "John description")
people[2] = person("Matt", "Matt.png", "Matt description")
for n = 1:peopleNumber
print(
"@def name$n = $(people[n].name)\n",
"@def image$n = images/people/$(people[n].image)\n",
"@def description$n = $(people[n].description)\n" )
end This above code generates the markdown file needed, but I am not sure how to link it to the html file! |
Hello @aminya! Ok so there's kind of two sides to your question (my interpretation): first side (reasonable?)Is there a for loop in JuDoc's templating --> No, not yet, but I think it could be supported, we'd have to be careful that it doesn't do infinite stuff but something like {{for (i, e) in enumerate(collection)}}
...
{{end}} where I've been meaning to work and improve JuDoc's templating capacity but so far I've kind of been stuck with fixing other things 😄 second side (a bit wacky?)This may actually be what you want 😋, you can use the code-evaluation feature of JuDoc to evaluate Julia code that itself generates JuDoc markdown that can then be processed (!); this is what the This may be a bit what you were thinking in your second post. Consider this example (simpler than yours but it should be straightforward to extend to your case) In ```julia:./ex
#hideall
for name in ("Shinzo", "Donald", "Angela", "Christine")
println("""
@@card
### $name
![]("$(lowercase(name)).jpg")
@@
""")
end
```
\textoutput{./ex} Notes:
This generates html the core part of which is: <div class="card"><h3 id="shinzo"><a href="/index.html#shinzo">Shinzo</a></h3> <img src="shinzo.jpg" alt="" /></div>
<div class="card"><h3 id="donald"><a href="/index.html#donald">Donald</a></h3> <img src="donald.jpg" alt="" /></div>
<div class="card"><h3 id="angela"><a href="/index.html#angela">Angela</a></h3> <img src="angela.jpg" alt="" /></div>
<div class="card"><h3 id="christine"><a href="/index.html#christine">Christine</a></h3> <img src="christine.jpg" alt="" /></div> What do you think? Let me know if you manage to get this to work
|
@aminya I'll close this for now (I've marked the issue in the todo list to add in the docs) but feel free to reopen or open another issue if this didn't work or you got stuck somewhere 😄 |
Is there a way to use loops to generate multiple html parts?
For example:
in which we can fill in
{{image i}}, {{name i}}, and {{text i}}
, by giving an structure or an array of strings to a loop.If
i
is for example 10, it should create 10 of these blocks. Or it can detecti
based on the size of input struct/array.The text was updated successfully, but these errors were encountered: