Parcourir la source

Make post component

master
Dylan Baker il y a 3 ans
Parent
révision
a42ba8ae66
4 fichiers modifiés avec 23 ajouts et 31 suppressions
  1. 19
    0
      templates/components.html
  2. 2
    18
      templates/index.html
  3. 1
    0
      templates/layout.html
  4. 1
    13
      templates/single.html

+ 19
- 0
templates/components.html Voir le fichier

1
+{% macro post(post, type) %}
2
+<div class="post">
3
+  <h3 class="post__heading">
4
+    <div class="post__links">
5
+      {% if type == "index" %}
6
+      <a class="post__link" href="/posts/{{ post.id }}">view</a>
7
+      {% endif %} {% if logged_in %}
8
+      <a class="post__link" href="/posts/{{ post.id }}/edit">edit</a>
9
+      {% endif %}
10
+    </div>
11
+    <span class="post__title">
12
+      {{ post.title }} :: {{ post.date }}
13
+    </span>
14
+  </h3>
15
+  <div class="post__body">
16
+    {{ post.body | safe }}
17
+  </div>
18
+</div>
19
+{% endmacro %}

+ 2
- 18
templates/index.html Voir le fichier

18
 {% endif %}
18
 {% endif %}
19
 
19
 
20
 <div class="posts">
20
 <div class="posts">
21
-  {% for post in posts %}
22
-  <div class="posts__post post">
23
-    <h3 class="post__heading">
24
-      <div class="post__links">
25
-        <a class="post__link" href="/posts/{{ post.id }}">view</a>
26
-        {% if logged_in %}
27
-        <a class="post__link" href="/posts/{{ post.id }}/edit">edit</a>
28
-        {% endif %}
29
-      </div>
30
-      <span class="post__title">
31
-        {{ post.title }} :: {{ post.date }}
32
-      </span>
33
-    </h3>
34
-    <div class="post__body">
35
-      {{ post.body | safe }}
36
-    </div>
37
-  </div>
38
-  {% endfor %}
21
+  {% for post in posts %} {{ components::post(post=post, type="index") }} {%
22
+  endfor %}
39
 </div>
23
 </div>
40
 {% endblock %}
24
 {% endblock %}

+ 1
- 0
templates/layout.html Voir le fichier

1
+{% import "components.html" as components %}
1
 <!DOCTYPE html>
2
 <!DOCTYPE html>
2
 <html lang="en">
3
 <html lang="en">
3
   <head>
4
   <head>

+ 1
- 13
templates/single.html Voir le fichier

1
 {% extends "layout.html" %} {% block content %}
1
 {% extends "layout.html" %} {% block content %}
2
 <div class="posts">
2
 <div class="posts">
3
-  <div class="posts__post post">
4
-    <h3 class="post__heading">
5
-      {% if logged_in %}
6
-      <a class="post__link" href="/posts/{{ post.id }}/edit">edit</a>
7
-      {% endif %}
8
-      <span class="post__title">
9
-        {{ post.title }} :: {{ post.date }}
10
-      </span>
11
-    </h3>
12
-    <div class="post__body">
13
-      {{ post.body | safe }}
14
-    </div>
15
-  </div>
3
+  {{ components::post(post=post, type="single") }}
16
 </div>
4
 </div>
17
 {% endblock %}
5
 {% endblock %}

Chargement…
Annuler
Enregistrer