Skip to content
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

Allow using loop variables in ReactiveHTML templates #2287

Merged
merged 2 commits into from
May 4, 2021

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented May 3, 2021

Allows making use of loop variables instead of the more cumbersome indexing syntax, e.g. this:

class Select(ReactiveHTML):

    options = param.List(doc="Options to choose from.")
    
    value = param.String(doc="Current selected option")
    
    _template = """
    <select id="select" value="${value}">
      {% for obj in options %}
      <option id="option-{{ loop.index0 }}">${objects[{{ loop.index0 }}]}</option>
      {% endfor %}
    </select>
    """

Can now be written as:

class Select(ReactiveHTML):

    options = param.List(doc="Options to choose from.")
    
    value = param.String(doc="Current selected option")
    
    _template = """
    <select id="select" value="${value}">
      {% for obj in options %}
      <option id="option">${obj}</option>
      {% endfor %}
    </select>
    """

@codecov
Copy link

codecov bot commented May 4, 2021

Codecov Report

Merging #2287 (1631f8b) into master (799132f) will increase coverage by 0.03%.
The diff coverage is 97.01%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2287      +/-   ##
==========================================
+ Coverage   83.64%   83.67%   +0.03%     
==========================================
  Files         183      183              
  Lines       21947    22007      +60     
==========================================
+ Hits        18357    18415      +58     
- Misses       3590     3592       +2     
Impacted Files Coverage Δ
panel/reactive.py 76.34% <91.66%> (+0.19%) ⬆️
panel/models/reactive_html.py 81.81% <96.66%> (+3.00%) ⬆️
panel/tests/test_reactive.py 99.07% <100.00%> (+0.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 799132f...1631f8b. Read the comment docs.

@philippjfr philippjfr merged commit 9d70cb9 into master May 4, 2021
@philippjfr philippjfr deleted the reactive_html_loop_variables branch May 4, 2021 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant