Hey guys, new MODx user here. Just been doing web stuff for the past month. Started out hand-coding with coffeecup. Moved to wordpress. Now I’m making what’s hopefully my last jump. I don’t understand half of what I read about MODx, but the parts I do understand, I love. I hope this community grows into the biggest CMS comunity there is.
On to my question... I read in the documentation that html should be kept in chunks and php should be kept in snippets. Snippets should only "return" values and not "echo" code. Is that a law? Or more of a guideline for keeping code clean?
The reason I ask, I am trying to generate dynamic content in a chunk. I considered using setPlaceholder in the php code, but I couldn’t figure out a way to generate a dynamic list with those placeholders back in the chunk.
Here’s the code I’m using to give you an idea of what I’m going for. It works as it is right now, I just want to make sure I won’t run into an error with it later down the line.
Could I split this up into 2 snippets? Is there a way to include a snippet inside a snippet so I’d be able to call the placeholders from the first snippet?
<?php
$i=0;
$sql = 'SELECT * FROM id_links WHERE 1';
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$modx -> setPlaceholder('offerurl'.$i,$row[offerurl]);
$modx -> setPlaceholder('name'.$i,$row[name]);
$modx -> setPlaceholder('campaignid'.$i,$row[campaignid]);
$modx -> setPlaceholder('description'.$i,$row[description]);
$modx -> setPlaceholder('instant'.$i,$row[instant]);
$modx -> setPlaceholder('commission'.$i,$row[commission]);
$modx -> setPlaceholder('countries_comma'.$i,$row[countries_comma]);
$modx -> setPlaceholder('reporting'.$i,$row[reporting]);
$i++;
}
$i = 0;
while ($i < 10)
{
$login_id = $modx->getLoginUserID();
$str = '<li><a href="[+offerurl'.$i.'+]'.$login_id.'">[+name'.$i.'+]</a></li>[+description'.$i.'+] - [+reporting'.$i.'+]';
mysql_real_escape_string($str);
echo ($str);
$i++;
}
return;
?>
Thanks for the CMS and thanks for any help on this.