В моей логике page.php:
Код: Выделить всё
$context = Timber::get_context();
$post = new TimberPost();
$context['page'] = $post;
$context['global'] = get_fields('options');
$context['protected'] = post_password_required($post->ID); // here i am trying to check if the current page is password protected and adding the check to the context
$context['password_form'] = get_the_password_form(); // grabbing the function to display the password form and adding it to the context
Timber::render( array(
'pages/page-' . $post->post_name . '.twig',
'pages/page.twig'
), $context );
Код: Выделить всё
{% if protected %}
{{ password_form }}
{% else %}
{% endif %}
Я также пробовал это в page.php:
Код: Выделить всё
$context = Timber::get_context();
$post = new TimberPost();
$context['page'] = $post;
$context['global'] = get_fields('options');
if ( post_password_required($post->ID) ) {
Timber::render('page-password.twig', $context);
} else {
Timber::render(array('pages/page-' . $post->post_name . '.twig', 'pages/page.twig' ), $context);
}
Подробнее здесь: https://stackoverflow.com/questions/525 ... timber-twi
Мобильная версия