UDT Display Child Pages

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
WDJames
Forum Members
Forum Members
Posts: 64
Joined: Tue Feb 13, 2018 1:09 pm

UDT Display Child Pages

Post by WDJames »

Hello all,

I'm using pages to add Case Studies to our site. I've been trying to modify the below UDT so that the items include the page's images. I understand that I can just use the Navigator module (which is what I've done in the past) but the reason I want to keep it as a UDT is so that I can give it some parameters like "pagelimit" and "sortorder" ( I'm hoping that the final module tag would look something like {case_studies category="commercial" pagelimit="3" sortby="DESC"}).

Code: Select all


$pagelimit = isset($params['pagelimit']) ? $params['pagelimit'] : '';
$sortby = isset($params['sortby']) ? $params['sortby'] : '';

global $gCms;
$manager =& $gCms->GetHierarchyManager();
$thisPage = isset($params['category']) ? $params['category'] : '';
$currentNode = &$manager->sureGetNodeByAlias($thisPage);

$nodes = $currentNode->getChildren();

if ($currentNode->hasChildren()) {
  echo '<ul class="casestudies">';
  foreach ($nodes|@array_slice:0:'.$pagelimit.' as $node) {
     $content = $node->getContent();
     $url = $content->GetURL();
     
     $image = $content->GetImage(); /* THIS DOESN'T WORK */
  
    if ($url == "#") { /* section header has no link by default */
      $url = "index.php?page=".$content->Alias();
    }
    echo "<li><a href=\"".$url."\">".$content->MenuText()."</a> </li>";

  }
  echo "</ul>";
}
I've tried looking for the method to get the page image but I've had no luck. Anyone have any ideas?

Thanks,

James
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1924
Joined: Mon Jan 29, 2007 4:47 pm

Re: UDT Display Child Pages

Post by Jo Morg »

I think you have a mix of issues there:
- it seems you are mixing PHP and Smarty syntax there;
- there is some legacy code that CMSMS doesn't support anymore;
- possibly some PHP typos or syntax errors;

I didn't test it but just corrected it to what it seemed a bit more logical and valid PHP code. Try it and give us some feedback:

Code: Select all

$pagelimit = isset($params['pagelimit']) ? $params['pagelimit'] : '';
$sortby = isset($params['sortby']) ? $params['sortby'] : '';

$manager = CMSMS()->GetHierarchyManager();
$thisPage = $params['category'] ?? '';
$currentNode = $manager->sureGetNodeByAlias($thisPage);

$nodes = $currentNode->getChildren();

if($currentNode->hasChildren())
{
  echo '<ul class="casestudies">';
  $tmp = array_slice($nodes, 0, $pagelimit);
  foreach($tmp  as $node)
  {
    $content = $node->getContent();
    $url     = $content->GetURL();
    
    $image = $content->GetImage();
    
    if('#' == $url)
    { /* section header has no link by default */
      $url = 'index.php?page=' . $content->Alias();
    }
    echo '<li><a href="' . $url . '">' . $content->MenuText() . '</a> </li>';
    
  }
  echo '</ul>';
}
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
WDJames
Forum Members
Forum Members
Posts: 64
Joined: Tue Feb 13, 2018 1:09 pm

Re: UDT Display Child Pages

Post by WDJames »

Hi Jo, thanks for the feedback - I thought I'd save some time by modifying an existing UDT rather than writing from scratch. Your corrections work and the code runs if I comment out the $image line, however if I leave it as it is, the $image = $content->GetImage(); still causes a Fatal error (because I made it up to show where I want to get the image):

<b>Fatal error</b>: Uncaught Error: Call to undefined method Content::GetImage() in ...

Is there a list of CMSMS methods that I can reference?

Thanks,

James
WDJames
Forum Members
Forum Members
Posts: 64
Joined: Tue Feb 13, 2018 1:09 pm

Re: UDT Display Child Pages

Post by WDJames »

I figured out how to get the image. I've replaced the code so instead of:

Code: Select all

$image = $content->GetImage();
I used

Code: Select all

$image = $content->GetPropertyValue('image');
Then I used an if statement to display a placeholder image if its blank.

Hope this helps someone else.

Thanks,

James
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1924
Joined: Mon Jan 29, 2007 4:47 pm

Re: UDT Display Child Pages

Post by Jo Morg »

Glad you figured it out. Thanks for posting it back to the community. 8)
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Post Reply

Return to “Modules/Add-Ons”