[SOLVED] Getting additional content-blocks from children

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
sgtstevil
Forum Members
Forum Members
Posts: 22
Joined: Wed Jan 13, 2010 3:26 pm

[SOLVED] Getting additional content-blocks from children

Post by sgtstevil »

I'm working on a website for a booking-agency (dj's). I can entrust them with adding pages for a DJ, but I want the parent-page to show a list of dj's with their photos and a genre. These are content_blocks and content_image in the template for the Artistpage. I found some code which will list the children in an unordered list, with title and link:

Code: Select all

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

$nodes = $currentNode->getChildren();

if ($currentNode->hasChildren()) {
  echo '<ul class="sectionlinks">';
  foreach ($nodes as $node) {
     $content= $node->getContent();
     $url = $content->GetURL();
    if ($url == "#") { /* section header has no link by default */
      $url = "artists/".$content->Alias();
    }
    echo "<li><a href=\"".$url."\">".$content->MenuText()."</a> </li>";

  }
  echo "</ul>";
}
Can anyone explain how i'd get one of the other content_blocks? I've already assigned artist_pic to $artist_pic in the template
Last edited by sgtstevil on Sat Feb 13, 2010 9:04 am, edited 1 time in total.
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm

Re: [OPEN] How do I get other values from children?

Post by RonnyK »

Check CGSimpleSmarty, that has some calls in its help to get the data of different blocks.

Ronny
sgtstevil
Forum Members
Forum Members
Posts: 22
Joined: Wed Jan 13, 2010 3:26 pm

Re: [OPEN] How do I get other values from children?

Post by sgtstevil »

RonnyK wrote: Check CGSimpleSmarty, that has some calls in its help to get the data of different blocks.

Ronny
Thanks! I'm not getting it to work however. I keep getting the error:

Fatal error: Call to a member function get_page_content() on a non-object in /usr/home/deb4806n5/domains/twig-bookings.com/public_html/lib/content.functions.php(771) : eval()'d code on line 13

The code looks like this atm:

Code: Select all

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

$nodes = $currentNode->getChildren();

if ($currentNode->hasChildren()) {
  echo '<ul class="sectionlinks">';
  foreach ($nodes as $node) {
     $content= $node->getContent();
     $url = $content->GetURL();
     $cgsimple->get_page_content($node,$artist_pic,$artist_picture)
    if ($url == "#") { /* section header has no link by default */
      $url = "artists/".$content->Alias();
    }
    echo "<li><a href="".$artist_picture."">".$content->MenuText()."</a> </li>";

  }
  echo "</ul>";
}
I think i'm taking a wrong approach here. Could someone set me off in the right direction?
sgtstevil
Forum Members
Forum Members
Posts: 22
Joined: Wed Jan 13, 2010 3:26 pm

Re: [still open :)] How do I get other values from children?

Post by sgtstevil »

Am I in the wrong forum? Can someone gimme a hand please? I just need a kick in the right direction and then i'll dig the rest out myself...
sgtstevil
Forum Members
Forum Members
Posts: 22
Joined: Wed Jan 13, 2010 3:26 pm

Re: [still open :)] How do I get other values from children?

Post by sgtstevil »

Seriously, this is quite a setback for me. I've found CMSMS to be the most useful CMS i've ever come across, but I just need a little bit of help to get started. I'd hoped to get the same kind of readiness to help as I did with silverstripe (which is a pig of a cms if you're not a real developer, but ppl on the forum are willing to answer even the noobiest of question), but I'm getting squat. Can anyone please explain why noone's helping me out here? Am I in the wrong forum? Is it too noob of a question to help me out? Wtf...
tomgsd
Forum Members
Forum Members
Posts: 74
Joined: Tue Feb 12, 2008 10:00 am

Re: [still open :)] How do I get other values from children?

Post by tomgsd »

I normally use a menu template to do this kind of thing.  Something like this in a Menu Manager template (called "Sub-Section List"):

Code: Select all

{if $count > 1}
{foreach from=$nodelist item=node}
{* Get the picture *}
{$cgsimple->get_page_content($node->alias,'Overview_Picture_(for_list_page)','overview_pic')}
{* Get the overview text *}
{$cgsimple->get_page_content($node->alias,'Overview_Text_(for_list_page)','overview_text')}
{* Show them *}
<div class="picture">{$overview_pic}</div>
<div class="text">{$overview_text}</div>
{/foreach}
{/if}
This goes in the content of the "header" page or the template with the following:

Code: Select all

{menu template='Sub-Section List' start_page=$page_alias}
Then in the template for each sub page create your content blocks (remember that cmsms replaces spaces with underscores in your content block names - see above):

Code: Select all

{content_image block='Overview Picture (for list page)' dir='images/section_header_pics' urlonly='true'}
{content block='Overview Text (for list page)'}	
A lot of problems can be solved in cmsms with smarty, there's often no need to bother with UDT's.  I actually did this recently for DJ listings as well!
Green Sheep Design Ltd. - www.greensheep.co.uk
sgtstevil
Forum Members
Forum Members
Posts: 22
Joined: Wed Jan 13, 2010 3:26 pm

Re: [SOLVED] Getting additional content-blocks from children

Post by sgtstevil »

Wow, that simple huh? Thanks a million!!!!! Now up and running on www.elevation-events.com :).
Post Reply

Return to “CMSMS Core”