Page 1 of 1

Using Variables in Comments Module [solved]

Posted: Sat Dec 01, 2007 6:17 pm
by kendo451
Website: http://benlueders.com

I am using the Comments / News Module combination to make a blog as per Elijah's method in the CMSMS documentation.

However, the client wants the ability to add comments right on the main blog page.  So, I've done that, but run into a problem.

In the Comments display template, there is a call to {ExpandCollapse} that requires a unique id for each news item on the page.  If the id is not unique, you get multiple expand collapse divs with the same div id.  I got it to "work" this way, but when you post a comment, it attaches to the wrong news article.

So, I need a variable that contains a unique id for the news item that called the comments module to pass to {ExpandCollapse id="$uniqueID" title="$addcomment"}

I tried $pageid but that didn't work.   Can someone point me to a list of the smarty-accessible variables in the Comments module, so I can answer this question myself?  But, if you just want to give me the answer, that's cool too.

Thanks!
Ken Griffith

More details

Posted: Sat Dec 01, 2007 6:42 pm
by kendo451
First, my news summary template calls the comments module using the following SMARTY tag:
{cms_module module='comments' number='5' modulename='News' emailfield=1 websitefield=1 pageid=$entry->id}

Note that I am passing the news $entry->id to the comment module hook "pageid".

Then, inside the Comment Display Template I have this:

{startExpandCollapse id="$entry->pageid" title="$addacomment"}

I changed id="name" to id="$entry->pageid".  This produces each expandable comment box to have the same id, because it renders in the HTML to:

pageid" class="expand">

You can see it, at the moment, at http://benlueders.com.

So, how do I correctly pass the news item id to the id hook of {startExapandCollapse} tag?

Thanks,
Ken Griffith

Re: Using Variables in Comments Module

Posted: Tue Sep 30, 2008 7:20 pm
by kendo451
Ok, I found the problem.  In order to be a valid xhtml page, the id has to start with a letter.

So to have each expand collapse box use the news-item id for the div id use this:

Code: Select all

{startExpandCollapse id="n$pageid" title="whatever"}
The 'n' prior to $pageid is appended.  You could use any string starting with a letter to achieve the same thing.