Categories > TinyButStrong general >

TBS Help [Conditional Block Display + MergeBlock()]

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Jarhead
Date: 2009-05-26
Time: 14:43

TBS Help [Conditional Block Display + MergeBlock()]

I want to conditionally display a block according to $block_id and MergeBlock() with information related to the specific $block_id.
When I try and make $block_id global, the template prints out the values of the initial $block_id and doesn't appropriately display MergeBlock()

When I load the template after defining $block_id, MergeBlock() points to an invalid object.
How can I acheive my desired result?

admin.php
<?php
require_once("connect.php");
include_once('tbs_class.php');
$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('templates/admin.tpl');
$TBS->MergeBlock('menu_block',$mysql_conn,'SELECT * FROM cms_pages') ;
if(!empty($_POST['submit']))
{
$block_id = 1;
//handle form
}

else
{
$block_id = 2;
$TBS->MergeBlock('page_block',$mysql_conn, sprintf("SELECT * FROM cms_pages WHERE id = %d", $_GET['id']?$_GET['id']:1));

}
$TBS->Show();
mysql_close($mysql_conn);
?>

admin.tpl
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>JarCMS [Holiday BETA]</title>
<link href="style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="chrometheme/chromestyle.css" />
<script type="text/javascript" src="chromejs/chrome.js">

/***********************************************
* Chrome CSS Drop Down Menu- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

</script>
</head>
<body>

<div id = "header">
<img src = "logo.png" alt = "JarCMS [Holiday BETA]" />
</div>
<div class = "chromestyle" id = "main_menu">
        <ul>
        <li><a href="#" rel = "edit_page">Edit Page</a></li>
        <li><a href="add.php" rel = "add_page">Add Page</a></li>
        </ul>
    </div>

    <div id = "edit_page" class = "dropmenudiv">
    <a href = "admin.php?id=[menu_block.id]">[menu_block.name]</a>
    </div>
    <script type="text/javascript">
    cssdropdown.startchrome("main_menu")
    </script>
   
<div id = "content">
<span>
<h1>Errr....</h1>
[onload_1;block=span;when [var.block_id]==1]
</span>
<span>
<h1>[page_block.name]</h1>
<br />
<form name = "page_form" method = "POST" action = "[var..script_name]">
<input type = "hidden" name = "page_id" value = "[page_block.id]" />

<h2>Name</h2>
<input type = "text" name = "page_name" value = "[page_block.name]"/>
<br />


<h2>Title</h2>
<input type = "text" name = "page_title" value = "[page_block.title]"/>
<br />

<h2>Content</h2>
<textarea name = "page_content" rows = "20" cols = "30" >
[page_block.content]
</textarea>
<br />
<br />
<input type = "submit" name = "submit" value = "Submit"/>
</form>
[onload_1;block=span;when [var.block_id]==2]
</span>
</div>
</body>
</html>
By: Skrol29
Date: 2009-05-26
Time: 15:32

Re: TBS Help [Conditional Block Display + MergeBlock()]

Hi Jarhead,

This is because you are defining $block_id after the template is loaded. [onload] tags are merged during LoadTemplate().
By: Anonymous
Date: 2009-05-27
Time: 05:54

Re: TBS Help [Conditional Block Display + MergeBlock()]

Yes, but if I load the template after $block_id is defined, then MergeBlock() doesn't work.
By: Skrol29
Date: 2009-06-01
Time: 23:54

Re: TBS Help [Conditional Block Display + MergeBlock()]

Hi,

>if I load the template after $block_id is defined, then MergeBlock() doesn't work.
> MergeBlock() points to an invalid object.
What is the error message you have then?