By: Per Nils
Date: 2013-10-30
Time: 23:45
|
sub block as key reference
Something that bother me is using sub block as more like key reference
Example :
$data['name'] = array('john', 'elvis', 'samantha');
$data['location'] = array('dead', 'probelly dead', 'alive');
$tpl = <<<EOT
[d;sub1=name;sub2=loc]
<table>
<tr>
<td> Names : </td>
<td> [d_sub1.val;block=td </td>
</tr>
<tr>
<td> Locations : </td>
<td> [d_sub2.val;block=td </td>
</tr>
</table>
EOT;
$tbs = new clsTinyButStrong;
$tbs->Source = $tpl;
$tbs->MergeBlock('d', $data);
echo $tbs->Source;
|
Will output :
Array
Names : [d_sub1.val;block=td]
Locations : [d_sub2.val;block=td]
|
A workaround is
$data['name'] = array('john', 'elvis', 'samantha');
$data['location'] = array('dead', 'probelly dead', 'alive');
$tpl = <<<EOT
<table>
<tr>
<td> Names : </td>
<td> [d_name.val;block=td] </td>
</tr>
<tr>
<td> Locations : </td>
<td> [d_location.val;block=td] </td>
</tr>
</table>
EOT;
$tbs = new clsTinyButStrong;
$tbs->Source = $tpl;
$tbs->MergeBlock('d_name', $data['name']);
$tbs->MergeBlock('d_location', $data['location']);
echo $tbs->Source;
|
But if you have a lot of table rows to merge it look a messy on the php side.
Is there some other way to achieve this in a nice readable solution?
|
By: Skrol29
Date: 2013-10-31
Time: 02:04
|
Re: sub block as key reference
Hi Per Nils,
Sub-blocks does work with simple subg-data.
The thing in your example is that in fact "d" is not defined as a block. There is no parameter "block" for "d".
In this case TBS processes a merge like MergeField(), and then sub-blocks are not supported.
The correct workaround is:
$data['name'] = array('john', 'elvis', 'samantha');
$data['location'] = array('dead', 'probelly dead', 'alive');
$tpl = <<<EOT
<table>
<tr>
<td> Names : [d;block=table;sub1=name;sub2=loc] </td>
<td> [d_sub1.val;block=td] </td>
</tr>
<tr>
<td> Locations : </td>
<td> [d_sub2.val;block=td] </td>
</tr>
</table>
EOT;
$tbs = new clsTinyButStrong;
$tbs->Source = $tpl;
$tbs->MergeBlock('d', array($data)); // note that $data is embedded in an array
echo $tbs->Source;
|
|
By: Per Nils
Date: 2013-10-31
Time: 06:51
|
Re: sub block as key reference
Nice .....
* edit *
maybe you should change the topic to something more "on topic" on this new thread.
Using sub block as key reference .... or similar
* edit *
|
By: Skrol29
Date: 2013-10-31
Time: 15:27
|
Re: sub block as key reference
done :)
|
|
Posting in progress.
Please wait...
|