简体   繁体   English

WordPress +木材+树枝

[英]Wordpress + Timber + Twig

in index.php (entry file) I have a $context["home-page"] = home_url(); index.php (入口文件)中,我有一个$context["home-page"] = home_url(); yet for some reason when I implement it as <a href="{{ home-page }}">hello.com</a>. 出于某种原因,当我将其实现为<a href="{{ home-page }}">hello.com</a>. When rendering, I get a "0" value in href attribute: hello.com 渲染时,我在href属性中得到一个“ 0”值:hello.com

when I dump that context value, I get this erroneous reply: 当我转储该上下文值时,会收到以下错误回复:

\\wp-content\\themes\\hello\\vendor\\twig\\twig\\lib\\Twig\\Extension\\Debug.php:50:int 0

Keep in mind that all the other contexts Work fine, such as: 请记住,所有其他上下文都可以正常工作,例如:

  • $context["parent_link"] = get_template_directory_uri();
  • $context["is_single"] = is_single();

Is this somethin familiar to any of you? 你们当中有些人熟悉吗?

Please try it this way: 请尝试这种方式:

$context["home_page"]

Instead of 代替

$context["home-page"]

In twig templates {{ home-page }} should be interpreted as a substraction of variable home with variable page . 在树枝模板中, {{ home-page }}应该解释为减去变量home和变量page

Edit: And like @DarkBee suggested you would have to define the variables before you can use them. 编辑:和@DarkBee一样,建议您必须先定义变量,然后才能使用它们。 That is why you get the error when debugging the context object. 这就是为什么在调试上下文对象时收到错误的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM