Page 1 of 1

PHP loop and Content_Props

Posted: Tue Mar 13, 2012 2:51 pm
by direct2digital
I'm trying to show some content_props values within a loop and am pretty sure I've tried everything.

The code I currently have is below. The fields in [] are those that are either standard content blocks or custom props.

Any assistance that can be given would be great.

Code: Select all

{php}
global $gCms;
$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['page_name'];
$currentNode = &$manager->sureGetNodeByAlias($thisPage);

$nodes = $currentNode->getChildren();

if ($currentNode->hasChildren()) {
  echo '<table border="0" cellspacing="0" cellpadding="0"> <thead>  <tr> <th>Product code</th><th>Description</th><th>Size</th><th>Unit of sale</th><th></th><th></th> </tr> </thead><tbody>';
  foreach ($nodes as $node) {
     $content= $node->getContent();
    echo "<form>
            <form><tr>
               <td>[Product_Code]</td>
               <td>[Content]</td>
               <td>[Product_Size]</td>
               <td>[Unit_of_Sale]</td>
               <td></td>
               <td></td>
            </tr></form>";
  }
  echo "
</tbody>
</table>";
}
{/php}

Re: PHP loop and Content_Props

Posted: Tue Mar 13, 2012 7:07 pm
by winkelman
Have you tried to change

Code: Select all

global $gCms
to

Code: Select all

$gCms = cmsms();

Re: PHP loop and Content_Props

Posted: Wed Mar 14, 2012 6:46 pm
by calguy1000
a: mixing php code and output styling is just 'bad form'... it's better to give the data to smarty and then just do layout and styling using smarty.

b: use $content->GetProperty('foo'); where 'foo' is defined in the 'block' argument of the page template. i.e: {content block='foo'} (or is one of the standard properties associated with a content page).

Re: PHP loop and Content_Props

Posted: Wed Mar 14, 2012 8:58 pm
by direct2digital
Thank you for your responses thus far.

I'm a newbie with Smarty as a whole so any more specific pointers you can give would be appreciated.