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

Reorder twig files #162

Merged
merged 11 commits into from
May 21, 2024
2 changes: 1 addition & 1 deletion 404.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
use Timber\Timber;

$context = Timber::context();
Timber::render('404.twig', $context);
Timber::render('templates/404.twig', $context);
5 changes: 2 additions & 3 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Timber\Timber;

$templates = array('archive.twig', 'index.twig');
$templates = array('templates/archive.twig', 'templates/index.twig');

$title = 'Archive';
if (is_day()) {
Expand All @@ -27,10 +27,9 @@
$title = single_tag_title('', false);
} elseif (is_category()) {
$title = single_cat_title('', false);
array_unshift($templates, 'archive-' . get_query_var('cat') . '.twig');
} elseif (is_post_type_archive()) {
$title = post_type_archive_title('', false);
array_unshift($templates, 'archive-' . get_post_type() . '.twig');
array_unshift($templates, 'templates/archive-' . get_post_type() . '.twig');
}

$context = Timber::context([
Expand Down
15 changes: 4 additions & 11 deletions author.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,10 @@

use Timber\Timber;

global $wp_query;
$context = Timber::context();

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

$context = Timber::context([
'title' => $title,
'author' => $author,
]);

Timber::render(array('author.twig', 'archive.twig'), $context);
Timber::render(array('templates/author.twig', 'templates/archive.twig'), $context);
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

use Timber\Timber;

$templates = array('index.twig');
$templates = array('templates/index.twig');

if (is_home()) {
array_unshift($templates, 'front-page.twig', 'home.twig');
array_unshift( $templates, 'templates/front-page.twig', 'templates/home.twig' );
}

$context = Timber::context([
Expand Down
3 changes: 1 addition & 2 deletions page.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
use Timber\Timber;

$context = Timber::context();
$post = $context['post'];

Timber::render(array('page-' . $post->post_name . '.twig', 'page.twig'), $context);
Timber::render('templates/page.twig', $context);
2 changes: 1 addition & 1 deletion search.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use Timber\Timber;

$templates = array('search.twig', 'archive.twig', 'index.twig');
$templates = array( 'templates/search.twig', 'templates/archive.twig', 'templates/index.twig' );

$context = Timber::context([
'title' => 'Search results for ' . get_search_query(),
Expand Down
9 changes: 5 additions & 4 deletions single.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

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

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

Timber::render($templates, $context);
5 changes: 0 additions & 5 deletions views/404.twig

This file was deleted.

9 changes: 0 additions & 9 deletions views/archive.twig

This file was deleted.

7 changes: 0 additions & 7 deletions views/author.twig

This file was deleted.

38 changes: 0 additions & 38 deletions views/base.twig

This file was deleted.

21 changes: 0 additions & 21 deletions views/comment.twig

This file was deleted.

3 changes: 0 additions & 3 deletions views/footer.twig

This file was deleted.

13 changes: 0 additions & 13 deletions views/head.twig

This file was deleted.

11 changes: 0 additions & 11 deletions views/index.twig

This file was deleted.

43 changes: 43 additions & 0 deletions views/layouts/base.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html {{ site.language_attributes }}>
{% block head %}
{% include 'partials/head.twig' %}
{% endblock %}

<body class="{{ body_class }}">
{{ function('wp_body_open') }}
<a class="skip-link screen-reader-text" href="#content">{{ _e('Skip to content') }}</a>
<header class="header">
{% block header %}
<div class="wrapper">
<h1 class="hdr-logo">
<a class="hdr-logo-link" href="{{ site.url }}">{{ site.name }}</a>
</h1>
<nav id="nav-main" class="nav-main">
{% include 'partials/menu.twig' with {
items: menu.get_items
} %}
</nav>
<!-- #nav -->
</div>
{% endblock %}
</header>

<section id="content" class="content-wrapper">
{% if title %}
<h1>{{ title }}</h1>
{% endif %}
<div class="wrapper">
{% block content %}
Sorry, no content
{% endblock %}
</div>
</section>

{% block footer %}
{% include 'partials/footer.twig' %}
{% endblock %}
{{ function('wp_footer') }}
{% do action('get_footer') %}
</body>
</html>
10 changes: 0 additions & 10 deletions views/menu.twig

This file was deleted.

14 changes: 0 additions & 14 deletions views/page.twig

This file was deleted.

64 changes: 0 additions & 64 deletions views/partial/pagination.twig

This file was deleted.

32 changes: 18 additions & 14 deletions views/comment-form.twig → views/partials/comment-form.twig
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<div class="comment-form">
<h3>Add comment</h3>
<form class="comment-form" method="post" action="{{ site.site_url~'/wp-comments-post.php' }}">
{% if user %}
<input type="hidden" name="email" value="{{ user.email }}">
<input type="hidden" name="author" value="{{ user.name }}">
<input type="hidden" name="url" value="{{ user.link }}">
<form class="comment-form" method="post" action="{{ site.link ~ '/wp-comments-post.php' }}">
{% if user %}
<input type="hidden" name="email" value="{{ user.email }}" />
<input type="hidden" name="author" value="{{ user.name }}" />
<input type="hidden" name="url" value="{{ user.link }}" />
{% else %}
<label>Email<br>
<input required name="email" type="email" id="email">
<label>
Email<br />
<input required name="email" type="email" id="email" />
</label>
<label>Name<br>
<input required name="author" type="text">
<label>
Name<br />
<input required name="author" type="text" />
</label>
<label>Website<br>
<input name="url" type="url">
<label>
Website<br />
<input name="url" type="url" />
</label>
{% endif %}
<label>Comment<br>
<label>
Comment<br />
<textarea placeholder="Leave a comment..." name="comment" cols="60" rows="3"></textarea>
</label>
<input name="comment_post_ID" value="{{ post.id }}" type="hidden">
<input name="comment_parent" value="{{ comment.ID|default('0') }}" type="hidden">
<input name="comment_post_ID" value="{{ post.id }}" type="hidden" />
<input name="comment_parent" value="{{ comment.id|default('0') }}" type="hidden" />
<button type="submit" name="Submit" class="btn">Send</button>
<button type="reset">Cancel</button>
<p>Your comment will be revised by the site if needed.</p>
Expand Down
Loading
Loading