Lookfar
Lookfar

Reputation: 65

passing (global) variable from one smarty template to another

I am using smarty version 2.6.26 and according to the docs by using {include 'file.tpl' scope='global'} or {include 'child_template.tpl' scope=parent} one should be able to access the variables contained in the child template and use them in the parent template.

as an example I have code like below in my child template:

  {capture assign="project_variable" name=project_data scope="global"}
  my text data here...
  {/capture}

The variable {$project_data} is available within this template now

In my parent (dashboard) template I am using:

 {include 'child_template.tpl' scope=global}

but if I try to use {$project_data} in the parent template it comes out blank. so it appears the variable set in the child template is local only?

according to the documentation at: http://www.smarty.net/docs/en/language.function.include.tpl

"You can use all variables from the including template inside the included template".

what am I missing here? thanks in advance for any insight.

Upvotes: 1

Views: 4746

Answers (2)

Lookfar
Lookfar

Reputation: 65

I was making the assumption that using {include file='mytemplate.tpl'} would find the "file" however it did not work until I used the full absolute path such as: {include file='/home/username/public_html/mysite/custom_template.tpl} and getting the variable using the format: {$smarty.capture.myvariable_name} so I answered my own question but Marcin got me on the right track so thanks for that!

I spoke too soon. it appears I can only capture static text and not a "{foreach}" loop any ideas greatly appreciated

Upvotes: 0

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

Sorry, but it seems you cannot do this in Smarty2. I tried a few ways but it doesn't work.

There is no scope property in Smarty3. You looked at documentation of Smarty3 and you should look at documentation for Smarty2

Upvotes: 1

Related Questions