Page 1 of 1

A bug in the startExpandCollapse tag? [solved]

Posted: Fri Sep 26, 2008 8:34 pm
by kendo451
I am using ExpandCollapse in a {comments} template so there are multiple instances of startExpandCollapse on the page and each requires a unique ID parameter.

So, I created a custom tag called {random_string length='n'} that generates a random string of 'n' characters.  I have tested it and it works fine in a page template.

I assigned the value of {random_string length='5'} to a variable $randstring, using two methods, and both work in my test page:
http://benlueders.com/test

Method 1

Code: Select all

{capture name='randstring'}{random_string length='10'}{/capture]
Method 2

Code: Select all

{random_string length='10' assign='randstring'}
The test page also has a test ExpandCollapse section like this:

Code: Select all

{random_string length='5' assign='randstring'}
{startExpandCollapse id="$randstring" title="$addacomment"}
...
bla bla bla
...
{endExpandCollapse}
This generates the following error message on the blog page:

Code: Select all

Error: The expand/collapse plugin requires that both parameters (id,title) are used.
I can't figure out why startExpandCollapse will not accept a variable for the id and name parameters.  Is my syntax wrong?

If someone could help me with my syntax here or, suggest a simpler way to pass the news item id through to the comments template so I could use that, I would be very grateful.

Thanks again!

Addition:

I checked the Smarty documentation and found that using double quotes, Smarty will attempt to expand any variables inside the quotes.  So id="$foo" should work if the variable $foo is declared.  id=$foo should also work.  See the next post, as I used various test cases for this bug.

Further Simplification of the problem with Test Cases

Posted: Tue Sep 30, 2008 6:01 pm
by kendo451
Further simplification of the problem with test cases:

Code: Select all

<h6>Case #1</h6>
{assign var='foo' value='test1'}
{startExpandCollapse id=$foo title=$foo}
<p>This is the text in the box</p>
{stopExpandCollapse}

<h6>Case #2</h6>
{assign var='foo' value='test2'} 
<p>The value of $foo is: {$foo}</p> 
{startExpandCollapse id="$foo" title="$foo"} 
<p>This is the text in the box.</p> 
{stopExpandCollapse}

<h6>Case #3</h6>
{title assign='foo'} 
{startExpandCollapse id=$foo title=$foo} 
<p>This is the text in the box.</p> 
{stopExpandCollapse}

<h6>Case #4</h6>
{title assign='foo'} 
<p>The value of $foo is: {$foo}</p> 
{startExpandCollapse id="Kung$foo" title="Kung$foo"} 
<p>This is the text in the box.</p> 
{stopExpandCollapse}
All of these test cases do work. So the problem must have been with my syntax.

Analysis

Relevant unsolved Threads:
http://forum.cmsmadesimple.org/index.php/topic,17447.0.html
http://forum.cmsmadesimple.org/index.php/topic,16429.0.html
http://forum.cmsmadesimple.org/index.php/topic,4330.0.html

Re: A bug in the startExpandCollapse tag?

Posted: Tue Sep 30, 2008 6:28 pm
by kendo451
I see in the original post several syntax errors:

1. used the tag {endExpandCollapse} instead of {stopExpandCollapse}

2. In order to use assign='foo' in the parameter list and have it actually assign the output to a variable, the plugin code itself must contain this:

Code: Select all

if( isset($params['assign']) )
	{
		global $gCms;
	    $smarty =& $gCms->GetSmarty();
	    $smarty->assign($params['assign'],$result);
	    return;
        }
I added that to the random_string function and it works now.