View previous topic :: View next topic |
Author |
Message |
rotee Smarty n00b
Joined: 08 Aug 2003 Posts: 3 Location: Bangkok Thailand
|
Posted: Fri Aug 08, 2003 6:48 am Post subject: Can I use the parameter in {include} function? |
|
|
I wanna include the page depend on my parameter, such as :
{include file"$myPage"}
Can I do like this and how?
Thank you,
|
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
|
Back to top |
|
davewolf Smarty Rookie
Joined: 25 Jan 2004 Posts: 5
|
Posted: Sun Jan 25, 2004 2:42 pm Post subject: |
|
|
Hi,
I have problem related to this issue, therefore I'm asking here.
Tested it as described in the manual. Works fine for {display ...}. {include file=$file_name} seems to work as well. But I always get a: Smarty error: unable to read resource: "" (for this example; tested with the demo page of the package).
Am I to ignore this, or to change anything?
Thanks in advance. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun Jan 25, 2004 3:07 pm Post subject: |
|
|
maybe $file_name is not set then. |
|
Back to top |
|
davewolf Smarty Rookie
Joined: 25 Jan 2004 Posts: 5
|
Posted: Mon Jan 26, 2004 11:36 am Post subject: |
|
|
messju wrote: | maybe $file_name is not set then. |
It is. It can be echoed without a problem, like...
{php}
$file_name = 'header.tpl';
echo $file_name;
{/php}
{include file=$my_name title=foo}
...from the index.tpl pf the demo page.
Tested it locally and on a remote server. I always get the correct echo and then this message:
Warning: Smarty error: unable to read resource: "" in /smarty/libs/Smarty.class.php on line 1144
No more problem if I switch back to...
{include file="header.tpl" title=foo}
BTW it's Smarty 2.6.0.
Any ideas?
TIA |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Jan 26, 2004 12:03 pm Post subject: |
|
|
make sure you have the value assigned: $smarty->assign('my_name', $file_name)
test in the template with "{$my_name|debug_print_var}" right before the {include}-tag. |
|
Back to top |
|
davewolf Smarty Rookie
Joined: 25 Jan 2004 Posts: 5
|
Posted: Mon Jan 26, 2004 12:36 pm Post subject: |
|
|
messju wrote: | make sure you have the value assigned: $smarty->assign('my_name', $file_name)
test in the template with "{$my_name|debug_print_var}" right before the {include}-tag. |
BTW, that was a typo on my side. It was actually:
{php}
$file_name = 'header.tpl';
echo $file_name;
{/php}
{include file=$file_name title=foo}
Tested different variable names, just in case some might be reserved and mixed things up when posting.
Anyway, I assigned the variable by Smarty standards, as you suggested, then it worked.
Let's see if I got this:
All variables used by Smarty inside a template file must be assigned properly - As for this example just setting it with PHP satisfies PHP, but don't work for Smarty. Thus the correct echo, but a Smarty error. No difference for {include}, right?
Sorry for the newbie questions...
TIA
Dave |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Jan 26, 2004 12:53 pm Post subject: |
|
|
right. you always have to assign variables, even from within {php} or from {include_php}:
[php:1:158ee89136]{php}
$file_name = 'header.tpl';
echo $file_name;
$this->assign('file_name', $file_name); /*
the template is displayed inside a method of smarty (mostly display())
so the $smarty object you called, is always "$this" inside php-tags */
{/php}
{include file=$file_name title=foo}[/php:1:158ee89136] |
|
Back to top |
|
davewolf Smarty Rookie
Joined: 25 Jan 2004 Posts: 5
|
Posted: Sat Jan 31, 2004 11:12 am Post subject: |
|
|
Thank you, Sir!
It's amazing people like you keep supporting fools like me besides your real work. |
|
Back to top |
|
|