Skip to content

Commit 2ddc5b9

Browse files
Levdbasgchtr
andauthored
Reorder twig files (#162)
* feat: move twigs into subfolders * feat: update html of twig files * feat: simplified php template files in getting the context Co-authored-by: Lukas Gaechter <[email protected]>
1 parent 0a6cb4d commit 2ddc5b9

40 files changed

+314
-312
lines changed

404.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
use Timber\Timber;
1010

1111
$context = Timber::context();
12-
Timber::render('404.twig', $context);
12+
Timber::render('templates/404.twig', $context);

archive.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use Timber\Timber;
1616

17-
$templates = array('archive.twig', 'index.twig');
17+
$templates = array('templates/archive.twig', 'templates/index.twig');
1818

1919
$title = 'Archive';
2020
if (is_day()) {
@@ -27,10 +27,9 @@
2727
$title = single_tag_title('', false);
2828
} elseif (is_category()) {
2929
$title = single_cat_title('', false);
30-
array_unshift($templates, 'archive-' . get_query_var('cat') . '.twig');
3130
} elseif (is_post_type_archive()) {
3231
$title = post_type_archive_title('', false);
33-
array_unshift($templates, 'archive-' . get_post_type() . '.twig');
32+
array_unshift($templates, 'templates/archive-' . get_post_type() . '.twig');
3433
}
3534

3635
$context = Timber::context([

author.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@
1111

1212
use Timber\Timber;
1313

14-
global $wp_query;
14+
$context = Timber::context();
1515

16-
$title = false;
17-
if (isset($wp_query->query_vars['author'])) {
18-
$author = Timber::get_user($wp_query->query_vars['author']);
19-
$title = 'Author Archives: ' . $author->name();
16+
if (isset($context['author'])) {
17+
$context['title'] = sprintf(__('Archive of %s', 'timber-starter'), $context['author']->name());
2018
}
2119

22-
$context = Timber::context([
23-
'title' => $title,
24-
'author' => $author,
25-
]);
26-
27-
Timber::render(array('author.twig', 'archive.twig'), $context);
20+
Timber::render(array('templates/author.twig', 'templates/archive.twig'), $context);

index.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
use Timber\Timber;
1515

16-
$templates = array('index.twig');
16+
$templates = array('templates/index.twig');
1717

1818
if (is_home()) {
19-
array_unshift($templates, 'front-page.twig', 'home.twig');
19+
array_unshift( $templates, 'templates/front-page.twig', 'templates/home.twig' );
2020
}
2121

2222
$context = Timber::context([

page.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@
1515
use Timber\Timber;
1616

1717
$context = Timber::context();
18-
$post = $context['post'];
1918

20-
Timber::render(array('page-' . $post->post_name . '.twig', 'page.twig'), $context);
19+
Timber::render('templates/page.twig', $context);

search.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Timber\Timber;
99

10-
$templates = array('search.twig', 'archive.twig', 'index.twig');
10+
$templates = array( 'templates/search.twig', 'templates/archive.twig', 'templates/index.twig' );
1111

1212
$context = Timber::context([
1313
'title' => 'Search results for ' . get_search_query(),

single.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
$context = Timber::context();
1313
$post = $context['post'];
14+
$templates = array('templates/single-' . $post->post_type . '.twig', 'templates/single.twig');
1415

1516
if (post_password_required($post->ID)) {
16-
Timber::render('single-password.twig', $context);
17-
} else {
18-
Timber::render(array('single-' . $post->ID . '.twig', 'single-' . $post->post_type . '.twig', 'single-' . $post->slug . '.twig', 'single.twig'), $context);
19-
}
17+
$templates = 'templates/single-password.twig';
18+
}
19+
20+
Timber::render($templates, $context);

views/404.twig

-5
This file was deleted.

views/archive.twig

-9
This file was deleted.

views/author.twig

-7
This file was deleted.

views/base.twig

-38
This file was deleted.

views/comment.twig

-21
This file was deleted.

views/footer.twig

-3
This file was deleted.

views/head.twig

-13
This file was deleted.

views/index.twig

-11
This file was deleted.

views/layouts/base.twig

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html {{ site.language_attributes }}>
3+
{% block head %}
4+
{% include 'partials/head.twig' %}
5+
{% endblock %}
6+
7+
<body class="{{ body_class }}">
8+
{{ function('wp_body_open') }}
9+
<a class="skip-link screen-reader-text" href="#content">{{ _e('Skip to content') }}</a>
10+
<header class="header">
11+
{% block header %}
12+
<div class="wrapper">
13+
<h1 class="hdr-logo">
14+
<a class="hdr-logo-link" href="{{ site.url }}">{{ site.name }}</a>
15+
</h1>
16+
<nav id="nav-main" class="nav-main">
17+
{% include 'partials/menu.twig' with {
18+
items: menu.get_items
19+
} %}
20+
</nav>
21+
<!-- #nav -->
22+
</div>
23+
{% endblock %}
24+
</header>
25+
26+
<section id="content" class="content-wrapper">
27+
{% if title %}
28+
<h1>{{ title }}</h1>
29+
{% endif %}
30+
<div class="wrapper">
31+
{% block content %}
32+
Sorry, no content
33+
{% endblock %}
34+
</div>
35+
</section>
36+
37+
{% block footer %}
38+
{% include 'partials/footer.twig' %}
39+
{% endblock %}
40+
{{ function('wp_footer') }}
41+
{% do action('get_footer') %}
42+
</body>
43+
</html>

views/menu.twig

-10
This file was deleted.

views/page.twig

-14
This file was deleted.

views/partial/pagination.twig

-64
This file was deleted.

views/comment-form.twig views/partials/comment-form.twig

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
<div class="comment-form">
22
<h3>Add comment</h3>
3-
<form class="comment-form" method="post" action="{{ site.site_url~'/wp-comments-post.php' }}">
4-
{% if user %}
5-
<input type="hidden" name="email" value="{{ user.email }}">
6-
<input type="hidden" name="author" value="{{ user.name }}">
7-
<input type="hidden" name="url" value="{{ user.link }}">
3+
<form class="comment-form" method="post" action="{{ site.link ~ '/wp-comments-post.php' }}">
4+
{% if user %}
5+
<input type="hidden" name="email" value="{{ user.email }}" />
6+
<input type="hidden" name="author" value="{{ user.name }}" />
7+
<input type="hidden" name="url" value="{{ user.link }}" />
88
{% else %}
9-
<label>Email<br>
10-
<input required name="email" type="email" id="email">
9+
<label>
10+
Email<br />
11+
<input required name="email" type="email" id="email" />
1112
</label>
12-
<label>Name<br>
13-
<input required name="author" type="text">
13+
<label>
14+
Name<br />
15+
<input required name="author" type="text" />
1416
</label>
15-
<label>Website<br>
16-
<input name="url" type="url">
17+
<label>
18+
Website<br />
19+
<input name="url" type="url" />
1720
</label>
1821
{% endif %}
19-
<label>Comment<br>
22+
<label>
23+
Comment<br />
2024
<textarea placeholder="Leave a comment..." name="comment" cols="60" rows="3"></textarea>
2125
</label>
22-
<input name="comment_post_ID" value="{{ post.id }}" type="hidden">
23-
<input name="comment_parent" value="{{ comment.ID|default('0') }}" type="hidden">
26+
<input name="comment_post_ID" value="{{ post.id }}" type="hidden" />
27+
<input name="comment_parent" value="{{ comment.id|default('0') }}" type="hidden" />
2428
<button type="submit" name="Submit" class="btn">Send</button>
2529
<button type="reset">Cancel</button>
2630
<p>Your comment will be revised by the site if needed.</p>

0 commit comments

Comments
 (0)