Personal tools
Namespaces
Variants
Actions

Design:Post.html

From Katapulta

Jump to: navigation, search

Acest template afișează pagina unui articol din Blog.

Dacă vrei să afișezi toate comentariile unui articol, prima data testezi daca articolul curent suportă comentarii. Iată un exemplu:

<h2>{{ post.title }}</h2>
<i>scris de {{ post.author}} la data de {{ post.creation_time }}</i>
<p>{{ post.content|nl2br }}</p>

{% if post.comments_denied == false %}
  
  {# Afiseaza lista de comentarii #}
  <h3>Comentarii</h3>
  {% if post.comments|length > 0 %}
    <ul id="comments-post_{{ post.id }}">
    {% for comment in post.comments %}
      <li>
        <i>Comentariul lui {{ comment.author }} din {{ comment.creation_time }}</i>
        <p>{{ comment.content|nl2br }}</p>
      </li>
    {% endfor %}
    </ul>
  {% else %}
    <p>Nu sunt comentarii la acest articol</p>
  {% endif %}
  
  
  {# Afiseaza formularul de adaugare a unui comentariu #}
  {% if posted_successfully == true %}
    <h4>{{ post_message }}</h4>
  {% endif %}
  
  <h3>Adauga un comentariu</h3>
  <form action="/post/{{ post.handle }}" method="POST" id="add-comment-form">
  <p>
    <label for="author">Numele tau</label>
    {{ comment_form.display_error('author') }}
    <input type="text" name="PostComment[author]" id="author" class="field {% if comment_form.has_error('author') %} error {% endif %}" value="{{ comment_form.author }}"/>
  </p>
  
  <p>
    <label for="content">Comentariu</label>
    {{ comment_form.display_error('content') }}
    <textarea name="PostComment[content]" id="content" cols="" rows="" class="{% if comment_form.has_error('content') %} error {% endif %}">{{ comment_form.content }}</textarea>
  </p>
  
  <p>
    <input type="submit" value="Adauga comentariu" name="submit" class="button"/>
  </p>
  </form>
    
{% endif %}

Variabile

În template-ul post.html pot fi accesate următoarele variabile:

  • post - articolul curent
  • comment_form
    - formularul de adăugare a unui comentariu; atribute:
    • comment_form.author
      - autorul comentariului
    • comment_form.content
      - conținutul comentariului
    • comment_form.has_error(atribut)
      - funcție care testează dacă
      atribut
      are erori
    • comment_form.display_error(atribut)
      - functie care afișează eroarea pentru
      atribut
  • posted_successfully
    - variabila de tip boolean care indică dacă comentariul a fost adăugat
  • post_message
    - mesajul de succes în cazul adăugării unui comentariu
  • toate variabilele globale