PHP loop and Content_Props

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
direct2digital
New Member
New Member
Posts: 2
Joined: Tue Mar 13, 2012 2:45 pm

PHP loop and Content_Props

Post 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}
winkelman
Forum Members
Forum Members
Posts: 32
Joined: Sun Dec 19, 2010 9:05 pm

Re: PHP loop and Content_Props

Post by winkelman »

Have you tried to change

Code: Select all

global $gCms
to

Code: Select all

$gCms = cmsms();
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: PHP loop and Content_Props

Post 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).
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
direct2digital
New Member
New Member
Posts: 2
Joined: Tue Mar 13, 2012 2:45 pm

Re: PHP loop and Content_Props

Post 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.
Post Reply

Return to “Developers Discussion”