-1

I created page-home-page.twig in my view folder of Timber template. However,

1- If the page home-page set as default wordpress home-page, The template file will not work.

2- If the page home-page set as normal page content, then now the template will be okay.

Can any one advise me where is the issue?

Please view Timber documentation.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Tariq Ahmed
  • 305
  • 3
  • 14

1 Answers1

1

I fixed it by doing the following:

1- In my WordPress theme folder /wp-content/themes/my-theme/ I created an Custom Page Template reference to this guide: Custom Page Templates

Using this code:

<?php
/**
 * Template Name: Video Template
 * Description: A Page Template for Home page Video CMS.
 */

defined('ABSPATH') or die;
use Timber\Timber;    
$gantry = Gantry\Framework\Gantry::instance();
$theme  = $gantry['theme'];

// We need to render contents of <head> before plugin content gets added.
$context              = Timber::get_context();
$context['page_head'] = $theme->render('partials/page_head.html.twig', $context);
$post                 = Timber::query_post();
$context['post']      = $post;
Timber::render(['page-' . $post->post_name . '.html.twig', 'page-hvideo.twig'], $context);

Where Timber::render(['page-' . $post->post_name . '.html.twig', 'page-hvideo.twig'], $context); pointing us to the new Timber page-hvideo.twig file under theme/view folder.

2- And in my Timber template view folder I added this file page-hvideo.twig with the following code:

{% extends "partials/page.html.twig" %}
{% set twigTemplate = 'single.html.twig' %}
{% set scope = 'single' %}
{% block content %}
    <div class="platform-content">
        <div class="content-wrapper">
            <section class="entry">
                {% include ['partials/content-' ~ scope ~ '-home-video.html.twig', 'partials/content-home-video.html.twig'] %}
            </section>
        </div> <!-- /content-wrapper -->
    </div>
{% endblock %}

Where {% include ['partials/content-' ~ scope ~ '-home-video.html.twig', 'partials/content-home-video.html.twig'] %} Will manage the home page custom template from view/partials folder under Timber theme folder as normal.

I hope this will help anyone else.

Thank you so much for everything you provided here.

EDITED: Please be sure after you add your Home Page custom page template to select it from your post editing screen in WordPress under Page Attributes section. enter image description here

TylerH
  • 20,799
  • 66
  • 75
  • 101
Tariq Ahmed
  • 305
  • 3
  • 14