Question about Smarty include function

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
NamantH

Question about Smarty include function

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Question about Smarty include function

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
NamantH

Re: Question about Smarty include function

Post 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 :)
NamantH

Re: Question about Smarty include function

Post 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.  :)
NamantH

Re: Question about Smarty include function

Post 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 :)
Post Reply

Return to “Developers Discussion”