我正在使用Timber & Twig来编写Wordpress主题。据我理解,在有N列的网格中输出帖子的惯用方法是使用batch过滤器:
{% block content %}
{% for row in posts | batch(3) %}
<div class='grid-3'>
{% for post in row %}
<div class='col'>
{% include ['tease-'~post.post_type~'.twig
我对Twig分机有问题。我想检查我的变量是否匹配正则表达式。但我错了。
我的树枝加长班:
<?php
// src/GL/HomeBundle/Twig/LastNameExtension.php
namespace GL\HomeBundle\Twig;
class LastNameExtension extends \Twig_Extension
{
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('lastName
我正在尝试创建一个自定义页面模板在WordPress中,使用木材/细枝。
我使用了下面的代码,不明白为什么它不能工作。木材文档没有提供具体的例子。
我有一个名为template- form -template.php的文件,用于几个表单页面。我更喜欢在admin中选择模板,而不是为每个页面段创建一个page-...twig。
<?php
/**
* Template Name: Form Template
* Description: Use this template for custom forms.
*/
$context = Timber::context();
$con
我使用的是和Wordpress (5.4.2版)。我已经安装了木材的作为样板。
木材利用Wordpress模板层次结构,允许您创建一个。
Page.php (木材起始主题中的默认主题)
/**
* The template for displaying all pages.
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on
我一直在摆弄Drupal8,在状态报告中看到它建议我添加Twig C扩展,在添加它之后,当在主题模板文件中使用Kint时,我开始收到以下错误。
Warning: file(/Users/jafacakes2011/Sites/site/recipe-hub/vendor/twig/twig/lib/Twig/Environment.php(403) : eval()'d code): failed to open stream: No such file or directory in Drupal\kint\Twig\KintExtension->kint() (line 78
我需要用一些HTML代码填充一个变量,并将它提供给我的base.html.twig文件。
为了达到这个目的,我做了一个小枝的延伸。这是我第一次使用树枝扩展,所以我不确定这是否是正确的做法。
以下是我到目前为止所拥有的:
扩展代码:
class GlobalFooterExtension extends \Twig_Extension
{
public function getFilters()
{
return array(
new \Twig_Filter_Function('GlobalFooter', array(
这是我的Perl脚本
use strict;
use warnings;
use XML::Twig;
use Data::Dumper;
sub xml2array{
my $path = shift;
my $twig = XML::Twig->new->parsefile($path);
return map { $_ -> att('VirtualPath') } $twig -> get_xpath('//Signals');
}
sub compareMappingToArray {
my $mapping = sh
我试图在模板文件中包含另一个带有预处理主题钩子变量的模板文件,但是它失败了。我检查了主题调试,它不包括示例的预处理主题挂钩。你能给我指点吗?
我在页面--Front.html.twig文件中添加了{% include 'example--p1.html.twig' %}。示例-p1.html.twig文件只有一个变量{{ test }}。此外,我还创建了一个预处理函数,将变量添加到页面模板中。代码如下。
function mytheme_preprocess_example__p1(array &$variables, $hook) {
$variables[
我使用Timber作为我的Wordpress主题,一段时间以来,我注意到Timber没有显示新创建的页面的内容。
下面是我的结构的一个例子:
我有一个work.php页面,它包含以下上下文:
$context = Timber::get_context();
$args = array(
// Get post type project
'post_type' => 'project',
// Get all posts
'posts_per_page' => -1,
// O
我有container.twig,包括component.twig,并传递一个名为‘’的对象。
在container.twig中:
{% set mock = {
title : "This is my title"
}
%}
{% include 'component.twig' with mock %}
这很好,但是我想将模拟数据移动到它自己的文件中。这不管用:
Container.twig
{% include 'component.twig' with 'mock.twig' %}
在mock.twig中
{%
我想将一个包含的Twig模板的输出作为参数传递给另一个包含的Twig模板,如下所示:
{% include 'MyBundle:Default:tpl1.html.twig' with {'item': include 'MyBundle:Default:tpl2.html.twig'} %}
不幸的是,这不起作用,因为语法是无效的。你知道如何像这样嵌套模板/将包含模板的输出存储在变量中吗?或者有没有其他方法来完成我想要做的事情?我想过在包含的模板中定义块,但似乎不可能从“外部”模板中覆盖它们……