Page 1 of 1

Question about Smarty include function

Posted: Mon Feb 13, 2006 7:53 pm
by NamantH
I am working on updating the Bookmarks module and I ran into a slight snag in the idea that I had so I figured i would toss it up and see if anyone knows.

In smarty you can use the {include file="blah.tpl"} to include external templates.

Now while building my template I have 3 files total:
1. adminpanel.tpl
2. listcats.tpl
3. listlinks.tpl

What I have code wise is:

Code: Select all

{$start_links_tab}
	{include file="$listlinkstpl"}
{$end_tab}
{$start_cats_tab}
	{include file="$listcatstpl"}
{$end_tab}
Then in my module I have

Code: Select all

		// Assign the included templates, so it knows where to get them... I hope
		$this->smarty->assign('listlinkstpl','listlinks.tpl');
		$this->smarty->assign('listcatstpl','listcats.tpl');
		
		// Display the populated template
        echo $this->ProcessTemplate('adminpanel.tpl');
Now when it comes up in the panel I get the following error:
string(82) "Smarty error: unable to read resource: "listlinks.tpl""

So im assuming that somewhere there is something that is causing issues.  I tried to find a call somewhere to reference where the tpl is... but no luck.

So any help would be greatful.  This is my first project working with smarty and cmsms... so please leave the noob bashing to a minimum, or take it to pm... I will laugh heartily there :)

thanks
nick

Re: Question about Smarty include function

Posted: Mon Feb 13, 2006 8:01 pm
by calguy1000
well, first you assigned the variable "listlinkstpl" to the value "listlinks.tpl"
so the correct smarty syntax would be {$linslinkstpl} whenever you wanted to refer to that
variable.

Now, wether smarty understands nested stuff like:
  {include file={$listlinkstpl}}
or
  {include file="{$listlinkstpl}"}

is another question.

You can, however look at the Banners, Uploads, FrontEndUsers, SelfReg, or Hitcounter modules to see an example of how I do it, slightly differently.

Re: Question about Smarty include function

Posted: Tue Feb 14, 2006 12:19 pm
by NamantH
calguy1000 wrote: well, first you assigned the variable "listlinkstpl" to the value "listlinks.tpl"
so the correct smarty syntax would be {$linslinkstpl} whenever you wanted to refer to that
variable.

Now, wether smarty understands nested stuff like:
  {include file={$listlinkstpl}}
or
  {include file="{$listlinkstpl}"}

is another question.

You can, however look at the Banners, Uploads, FrontEndUsers, SelfReg, or Hitcounter modules to see an example of how I do it, slightly differently.
actually the way i have it is correct.  The {include file=""} function is a smarty function.  It is properly changing the variable to the data... it is not, however, loading the template.

the reason i can see is because it is referencing the template directory through something... so I need to figure out how to preface the tpl file to get it to load :)

Re: Question about Smarty include function

Posted: Tue Feb 14, 2006 12:29 pm
by NamantH
Ok I figured it out.  What you need to do is to preference the template file with some stuff pointing to the generic template file.

found this in class.modue.inc.php

Code: Select all

'module_file_tpl:'.$this->GetName().';listlinks.tpl'
this is how you would reference an included file.  :)

Re: Question about Smarty include function

Posted: Wed Feb 15, 2006 12:10 pm
by NamantH
Patricia wrote: Hi Nick!
Glad to see all what you did so far, I'll try your svn version later today.
Im not done with the conversion to templates yet... but will be by the end of today.

and there are a couple of minor bugs that I need to track down :)