UBB.Dev
This is a UBB code/template behavior specific question (I think) and I hope this is the right place to ask this.

Anyway, I was looking into tweaking some code to allow our users to hide "closed" topics (a.k.a. "Locked".) Some background is here: http://www.ubbcentral.com/forums/ubbthreads.php/ubb/showflat/Main/41549/Number/198017

I've got it where there is a check-box under Display Options at the bottom of the post list titled "Hide locked topics." It works where I can click this button, click Change, and the topic list reloads with the locked threads not displayed. But, the button state does not stay checked after each reload at this point. So, this brings me to my question.

How would I get the value that I pass in with this checkbox back in to set the state back to checked?

More detail here...

In postlist.tpl, I added a checkbox option as follows (this would be after the existing form elements):
Code
<br />
Hide locked topics: <input type="checkbox" value="1" name="hidelocked" {if $hidelocked=="1"}CHECKED{/if} class="form-checkbox" />

The "if" isn't working, as I don't know how to get that hidelocked back in to this point.

The following changes are made in postlist.inc.php... after the "order" line, which should be around 41, I added the following:

Code
"hidelocked" => array("hidelocked","both","int"),

On about line 63, which should be right after "// Define any necessary variables" line, I added the following:

Code
$hidelockval = "";

Then after line 109 (after the variable declarations), add the following code:

Code
	if (!$hidelocked) { $hidelocked = 0; }

if ($hidelocked && ($_SESSION['myprefs']['hidelocked'] != $hidelocked)) {
$_SESSION['myprefs']['hidelocked'] = $hidelocked;
}

//If we are hiding locked threads, add the query string
if ($hidelocked == "1") {
$hidelockval = "and t1.TOPIC_STATUS = 'O'";
}

Now, the myprefs stuff in there was "fishing" trying to see if that's how to share the values between the various components (includes, templates, etc.)

Then after around line 746 or so (all these numbers change as more is added, etc.), which should be "t1.TOPIC_IS_STICKY...", I added the following to expand the query to exclude the closed topics:

Code
$hidelockval

So, I realize there are opportunities in the code (I've not used PHP much before, and don't know the framework I'm working in with the templates, etc.,) but I'm sure there is something easy I'm missing. After all, everything is easy 10 seconds after you figure it out.

Thanks much!
you really need to just inform smarty of the variable..

look towards the bottom and find

Code

$smarty_data = array(
"catrow" => array(0=>array('CatId'=>$Board)),
..

add a row that pass your $hidelocked from the .inc.php to the tpl.

like so (add this line):
Code

"hidelocked" => $hidelocked,

now smarty (the .tpl) knows about the value of $hidelocked from the script..

good luck,
SD

oh, and there's also a file in your /scripts directory called sample.inc.php that is commented and will explain a lot of what isn't documented anywhere. well worth a read wink
Posted By: tpro Re: Passing variables to/fro includes, templates, - 09/24/2007 11:28 PM
Yep... everything is easy 10 seconds after you figure it out wink Thanks much!
© UBB.Developers