Skip to content

Instantly share code, notes, and snippets.

@jarednova
Last active July 26, 2024 12:09
Show Gist options
  • Save jarednova/dc75030fd2c7dd6fe52a6fef459c450e to your computer and use it in GitHub Desktop.
Save jarednova/dc75030fd2c7dd6fe52a6fef459c450e to your computer and use it in GitHub Desktop.
Timber Hello World
{# This is a Twig comment, it won't output to the browser #}
<html>
<head>
<title>{{ wp_title }}</title>
</head>
{% block content %}
<!-- This will be overwritten by the content block in the inheriting .twig file -->
{% endblock %}
</html>
{# This template inherits from `base.twig` #}
{% extends "base.twig" %}
{% block content %}
<h1 class="big-title">{{ foo }}</h1>
<h2 class="post-title">{{ post.title }}</h2>
<img src="{{ post.thumbnail.src }}" />
<div class="body">
{{ post.content }}
</div>
{% endblock %}
<?php
/* this will send data from WordPress to the twig files we created */
$context = Timber::get_context();
$context['foo'] = 'BAR!';
$context['post'] = new Timber\Post();
Timber::render('templates/hello-world.twig, $context);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment