Php 将(全局)变量从一个smarty模板传递到另一个smarty模板

Php 将(全局)变量从一个smarty模板传递到另一个smarty模板,php,templates,smarty,smarty2,Php,Templates,Smarty,Smarty2,我正在使用smarty版本2.6.26,根据文档,通过使用{include'file.tpl'scope='global'}或{include'child_template.tpl'scope=parent}应该能够访问子模板中包含的变量并在父模板中使用它们 例如,我的子模板中有如下代码: {capture assign="project_variable" name=project_data scope="global"} my text data here... {/captur

我正在使用smarty版本2.6.26,根据文档,通过使用{include'file.tpl'scope='global'}或{include'child_template.tpl'scope=parent}应该能够访问子模板中包含的变量并在父模板中使用它们

例如,我的子模板中有如下代码:

  {capture assign="project_variable" name=project_data scope="global"}
  my text data here...
  {/capture}
变量{$project_data}现在在此模板中可用

在我的家长(仪表板)模板中,我正在使用:

 {include 'child_template.tpl' scope=global}
但是如果我尝试在父模板中使用{$project_data},结果是空的。 那么子模板中的变量集似乎只是局部变量

根据以下文件:

“您可以在包含的模板中使用包含模板中的所有变量”

我错过了什么?
提前感谢您提供的任何见解。

很抱歉,您在Smarty2中似乎无法做到这一点。我试过几种方法,但都不管用


Smarty3中没有
范围
属性。您查看了Smarty3的文档,应该查看一下

我假设使用{include file='mytemplate.tpl'}可以找到“文件” 但是,直到我使用完整的绝对路径(例如: {include file='/home/username/public_html/mysite/custom_template.tpl} 并使用以下格式获取变量:{$smarty.capture.myvariable_name} 所以我回答了我自己的问题,但是Marcin让我走上了正确的道路,所以谢谢你

我说得太快了。似乎我只能捕获静态文本,而不能捕获“{foreach}”循环
非常受欢迎的任何想法

smarty2的文档似乎是一样的:我的错误,但是smarty2的文档似乎是一样的:quote:“这意味着您可以在包含的模板中使用包含模板中的所有变量”。还是我误解了?根据这一点:可以为smarty2重用{$smarty.capture.project_data}之类的变量,但我也无法让它工作。啊哈!我刚刚尝试了模板的完整路径:{include file='/home/username/public_html/mysite/custom_templates/child.tpl}并使用了{$smarty.capture.project_data},结果成功了:)