<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0'>
	<channel>
		<title>cotonti.com : Data to TPL with AJAX question</title>
		<link>https://www.cotonti.com</link>
		<description>Son konu mesajları</description>
		<generator>Cotonti</generator>
		<language>en</language>
		<pubDate>Fri, 17 Apr 2026 17:39:23 -0000</pubDate>

		<item>
			<title>GHengeveld</title>
			<description><![CDATA[<p>
	Within the foreach, you need to do a parse('MAIN.TEST_ROW'), not an out().</p>
<p>
	At the end of your file, you need to do this:</p>
<pre class="brush:php;">
$t-&gt;parse('MAIN');
$t-&gt;out('MAIN');</pre>
<p>
	Usually you use out() only once: for the MAIN block at the end of your php code.</p>
<p>
	You can omit the 'MAIN' in out(), because it's the default value. To seperate your html code for a=update you may want to add the UPDATE block. Also, you'll often want to be able to show a message if there aren't any results:</p>
<pre class="brush:php;">
if ($a == 'update') {
    $rows = $res-&gt;fetchAll();
    if ($rows) {
        foreach ($rows as $row) {
            $t-&gt;assign(array(
                'TEST_USERNAME' =&gt; cot_build_user($row['test_userid'], htmlspecialchars($row['test_username'])),
                'TEST_MESSAGE' =&gt; cot_parse($row['test_message'], $cfg['plugin']['comments']['markup']),
                'TEST_DATE' =&gt; cot_date('M jS', $row['test_date']),
                'TEST_DATETIME' =&gt; cot_date('G:i', $row['test_date'])
            ));
            $t-&gt;parse('MAIN.UPDATE.ROWS.ROW');
        }
        $t-&gt;parse('MAIN.UPDATE.ROWS');
    } else {
        $t-&gt;parse('MAIN.UPDATE.NO_ROWS');
    }
    $t-&gt;parse('MAIN.UPDATE');
}
$t-&gt;parse('MAIN');
$t-&gt;out();</pre>
<p>
	A complete tpl could look like this:</p>
<pre class="brush:java;">
&lt;!-- BEGIN: MAIN --&gt;
&lt;!-- BEGIN: UPDATE --&gt;
&lt;div id="update"&gt;
  &lt;!-- BEGIN: ROWS --&gt;
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Username&lt;/th&gt;
        &lt;th&gt;Message&lt;/th&gt;
        &lt;th&gt;Date&lt;/th&gt;
        &lt;th&gt;Datetime&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;!-- BEGIN: ROW --&gt;
      &lt;tr&gt;
        &lt;td&gt;{TEST_USERNAME}&lt;/td&gt;
        &lt;td&gt;{TEST_MESSAGE}&lt;/td&gt;
        &lt;td&gt;{TEST_DATE}&lt;/td&gt;
        &lt;td&gt;{TEST_DATETIME}&lt;/td&gt;
      &lt;/tr&gt;
      &lt;!-- END: ROW --&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;!-- END: ROWS --&gt;
  &lt;!-- BEGIN: NO_ROWS --&gt;
  None
  &lt;!-- END: NO_ROWS --&gt;
&lt;/div&gt;
&lt;!-- END: UPDATE --&gt;
&lt;!-- END: MAIN --&gt;</pre>
]]></description>
			<pubDate>Per, 04 Eki 2012 06:52:29 -0000</pubDate>
			<link><![CDATA[https://www.cotonti.com/tr/forums?m=posts&q=7140&d=0#post35726]]></link>
		</item>
		<item>
			<title>Twiebie</title>
			<description><![CDATA[<p>
	I'm trying to get data into a TPL from a PHP file with AJAX.</p>
<p>
	The code I currently have is as following:</p>
<p>
	This is the JavaScript bit:</p>
<pre class="brush:jscript;">
$(document).ready(function() {
    function updateTesting(){
        ajaxSend({
            method: "GET",
            url: 'index.php?r=test&amp;a=update',
            data: "",
            divId: 'test_div'
        });
    }
    updateTesting();</pre>
<p>
	And test.ajax.php:</p>
<pre class="brush:php;">
if ($a == 'update') {
	foreach ($res-&gt;fetchAll() as $row) {
		$t-&gt;assign(array(
			'TEST_USERNAME' =&gt; cot_build_user($row['test_userid'], htmlspecialchars($row['test_username'])),
			'TEST_MESSAGE' =&gt; cot_parse($row['test_message'], $cfg['plugin']['comments']['markup']),
			'TEST_DATE' =&gt; cot_date('M jS', $row['test_date']),
			'TEST_DATETIME' =&gt; cot_date('G:i', $row['test_date'])
		));
		$t-&gt;parse('MAIN.TEST_ROW');
	}
}</pre>
<p>
	The TPL:</p>
<pre class="brush:xml;">
&lt;!-- BEGIN: MAIN --&gt;

&lt;div id="test_div"&gt;
&lt;!-- BEGIN: TEST_ROW --&gt;
	{TEST_USERNAME}
	{TEST_MESSAGE}
	{TEST_DATE}
	{TEST_DATETIME}
&lt;!-- END: TEST_ROW --&gt;
&lt;/div&gt;

&lt;!-- END: MAIN --&gt;</pre>
<p>
	For some reason it just doesn't display what I assign to MAIN.TEST_ROW.<br />
	What am I missing here?</p>
<p>
	When I do a simple echo for testing like shown below it does output the data in the TPL with AJAX.</p>
<pre class="brush:php;">
if ($a == 'update') {
	foreach ($res-&gt;fetchAll() as $row) {
		echo $row['test_message'];
	}
}</pre>
<p>
	Thanks.</p>
<p>
	<strong>Added 1 hours later:</strong></p>
<p>
	Hmm, it sort of works when I add to the foreach loop both parse and out:</p>
<pre class="brush:php;">
$t-&gt;parse('MAIN.TEST_ROW');
$t-&gt;out('MAIN.TEST_ROW');</pre>
<p>
	But I'm wondering if this is the correct way?</p>
<p><strong>Added 2 days later:</strong></p><p>
	Bump.</p>
]]></description>
			<pubDate>Pzt, 01 Eki 2012 22:05:55 -0000</pubDate>
			<link><![CDATA[https://www.cotonti.com/tr/forums?m=posts&q=7140&d=0#post35703]]></link>
		</item>
	</channel>
</rss>