Categories > TinyButStrong general >

how to code 2 repeating blocks in a HTML page

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: michael
Date: 2004-08-30
Time: 08:21

how to code 2 repeating blocks in a HTML page

Hi

I have a HTML page that has 2 variations of a form on the same page. When the page is loaded, one variation of the form is shown via visibility="visible" & the other variation is set to hidden using visibility="hidden".

Each of these form variations has a select box that I am populating using TBS (see HTML snippet below). This select box is used in each variation, and I want it to have the same option content in each variation. As you'll see, I am using the same setup, i.e.

<option value="[categories.categoryID]">[categories.category;block=option]</option>

in each form variation in the HTML.

<div id="simple" style="visibility:visible;z-index:1;">

    <form action="add_new_menuitem.php" method="post" name="simple">

        <table width="200" border="0" cellspacing="2" cellpadding="0">

            <tr>
                <td>category:</td>
                <td>
                    <select name="categoryid" size="1">
                        <option value="[categories.categoryID]">[categories.category;block=option]</option>
                    </select>
                </td>

            </tr>
       
            .... stuff deleted ....

        </table>

    </form>
</div>

<div id="advanced" style="position:relative;top:-175;visibility:hidden;">

    <form action="add_new_menuitem.php" method="post" name="advanced">

        <table width="200" border="0" cellspacing="2" cellpadding="0">

            <tr>
                <td>category:</td>
                <td>
                    <select name="categoryid" size="1">
                        <option value="[categories.categoryID]">[categories.category;block=option]</option>
                    </select>
                </td>
            </tr>

            .... stuff deleted ....

    </table>

    </form>
</div>

This is what I have in the PHP part:


.. db stuff delete

$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('setup_menuitems.htm');

$TBS->MergeBlock('categories', $connection_id, $categories_qry);
$TBS->MergeBlock('menuitem', $connection_id, $menuitems_qry);

mysql_close($connection_id);

$TBS->Show() ;

However I see I get a very strange result when the HTML page is merged & displayed. I found out it is to do with the way I currently setup the template for select in both variations of the form. If I remove the selects, the problem goes away of course.

I found out that the workaround is to create 2 separate mergeblocks like follows & update the HTML template accordingly, however I think that is not efficient since the same query will be called twice.

$TBS->MergeBlock('categories1', $connection_id, $categories_qry);
$TBS->MergeBlock('categories2', $connection_id, $categories_qry);

$TBS->Show() ;

Is there a better way that I can setup the HTML template to avoid this workaround?

Thanks

Regards

Michael.
By: Skrol29
Date: 2004-08-30
Time: 12:09

Re: how to code 2 repeating blocks in a HTML page

Hi Michael,

You're right. When two blocks have the same name, they behave like they are two sections of the same block. And they are stuck when merged. That explains the strange result you can observe.

The normal issue is to do whan you do.

There is a tip that enables you to use only one blocn name , and only one MergeBlock call : add the parameter p1='' in the block definitions. Then they will considered as sub-block, and query will be recalled for each of them.

If you want to not call the query twice, you can save the result of the query by your own in an array, and then merge the two blocks with the array.