Page 1 of 2
[Solved] Displaying partial child content within parent page
Posted: Sun Dec 07, 2008 11:07 am
by Weon
Firstly, as this is my first post, I will do the usual sucking up! Only kidding! In all seriousness, CMSMS is awesome. Until now I have mostly used WordPress (am I allowed to mention that name round here?) but required more flexibility in my site build. CMSMS has supplied that in spades so big thanks for all your hard work. Rest assured that when I get paid, you will too
Now on to my problem/question.
I am a designer, not a programmer. This means that solutions that may be obvious to others may take me a while to solve. This one has me stumped though.
Is there a way to use MenuManager (or anything else for that matter) to not only display the content for a page but also a list of the child pages with a set number of characters from the child pages content block? In case that doesn't really make sense I am after something like this:
Page Title
Page content here
Child Page 1 title (as link)
First 300 chars of Child Page 1 content with More... link at the end
Child Page 2 title (as link)
First 300 chars of Child Page 2 content with More... link at the end
Child Page 3 title (as link)
First 300 chars of Child Page 3 content with More... link at the end
Etc.
My reason for doing this is that I only want to have my client be able to edit the content blocks of each site and have all parent/child menu type options be automated.
I apologise if this is in the wrong forum - feel free to move it if required.
Re: Displaying partial child content within parent page
Posted: Sun Dec 07, 2008 8:46 pm
by JeremyBASS
I had a brain wave...
Just tested it and it works....
So put the Summary in the Extra Page Attribute 1: of options.....
make UDT name ChildrenANDcontent_Of_current and place that in the page you want the child page listings...
ad this to the UDT
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();
$page_alias = $content->Alias();
$cgsimple = $smarty->get_template_vars('cgsimple');
$Sum = $cgsimple->get_page_content($page_alias, 'extra1');
$url = $content->GetURL();
if ($url == "#") { /* section header has no link by default */
$url = "index.php?page=".$content->Alias();
}
echo "<li><a href=\"".$url."\" >".$content->MenuText()."</a> <br/>".$Sum."</li>";
}
echo "</ul>";
}
you now have what has been asked about at least 50 time I swear... even by me
Cheers
jeremyBass
proof
http://www.corbensproducts.net/
you can buy me a beer in the blogs

Re: Displaying partial child content within parent page
Posted: Sun Dec 07, 2008 11:13 pm
by nhaack
Hi Weon,
there are some cases where such things have been solved with the content_dump plug-in. Search the forum for "content_dump" or see
this wiki page for some basic information.
Content_dump was created to build automated index pages amongst other things. See this thread that comes close to your case and use them as a starting point:
http://forum.cmsmadesimple.org/index.php/topic,28313.0.html. There are some more posts on the usage but they are mostly German (but you might get the code

).
The plug-in takes a lot of optional parameters, play around to find what best suits your needs. I recommend HTML stripping to be activated if you want to truncate the real page content - alternatively, use extra content-blocks for summaries/abstracts. The later allows you to write precise teasing-texts for the sub-pages instead of getting the first X words.
So at the end /after installing the plug-in), you put this in your index-template (you might want to fancy up the HTML and smarty):
IF NO EXTRA CONTENT BLOCKS -> Shortening text
Code: Select all
{content_dump start_id=$content_id exclude="$content_id" html="strip"}
{foreach from=$dump item=dump}
<h4>{$dump->content->title}</h4>
<span>{$dump->created->date}</span><br />
<p>{$dump->content->data|truncate:300}</p>
<a href="{$dump->content->alias}.htm">go to content page</a>
<hr />
{/foreach}
IF EXTRA CONTENT BLOCKS - use additional block
Code: Select all
{content_dump start_id=$content_id exclude="$content_id" block_name="summary"}
{foreach from=$dump item=dump}
<h4>{$dump->content->title}</h4>
<span>{$dump->created->date}</span><br />
<p>{$dump->content->data}</p>
<a href="{$dump->content->alias}.htm">go to content page</a>
<hr />
{/foreach}
Let me know if that could do the trick for you.
Best
Nils
Re: Displaying partial child content within parent page
Posted: Mon Dec 08, 2008 9:26 am
by Weon
@jeremyBass - This looks promising but I am wanting to keep the amount of content entry that the user has to make to a minimum so simply using the first X characters of the content is probably the way forward for me. Also, I'm not sure what you mean by a UDT - is that a new tag that I would need to define (I'm guessing User Defined Tag)? Sorry - I am totally new to this so may appear to be a bit slow!
@Nils - This looks like it could be what I'm after. It certainly looks to be an easy solution to my tiny little mind! I'll have a play and see how I get on.
@everyone - I apologise for posting a request that you have already seen - I did try searching the documentation and the forums first but drew a blank. Searching for things related to a system that is all new does mean that you are not really sure what you should be searching for!
Re: Displaying partial child content within parent page
Posted: Mon Dec 08, 2008 1:51 pm
by calguy1000
This should be very simple with the CGSimpleSmarty module installed
{$cgsimple->get_children('',false,'children')}
{foreach from=$children item='child'}
{$cgsimple->get_page_content($child,'','')|truncate:300}
{/foreach}
Re: Displaying partial child content within parent page
Posted: Mon Dec 08, 2008 2:43 pm
by Weon
Hi CalGuy - Is it possible to strip the HTML from the output using your method?
Re: Displaying partial child content within parent page
Posted: Mon Dec 08, 2008 2:48 pm
by JeremyBASS
for what it's worth... I have found that pulling text but X number has cause a few issues when it's the client writing the text and making edits... this is why I suggested what I did... forcing them to think about what the Summary will be has always lead to better sounded ones as well.... also... I make that same call as the description in the meta tags... so dual propose for me..
cheers
jeremyBass
Re: Displaying partial child content within parent page
Posted: Mon Dec 08, 2008 2:53 pm
by calguy1000
{$cgsimple->get_children('',false,'children')}
{foreach from=$children item='child'}
{$cgsimple->get_page_content($child,'','')|strip_tags|truncate:300}
{/foreach}
Re: Displaying partial child content within parent page
Posted: Mon Dec 08, 2008 3:27 pm
by JeremyBASS
what's great is there is 3+ ways to d the same thing... probably way more... that's why I love CMSMS...
One side note about the strip_tags... that doesn't strip JS... had a client add a JS function in the first lines of the content block which at the time I was doing something like this for the meta tags ... and it kept pulling the JS over in the description
A Content block for the description meta tag... big issue for the client... plus what else is Extra Page Attribute 1: of options gone to be used for

j/p... For me my clients are willing to write that little extra, most copying and pasting form what was just placed... but I've had some that wouldn't... in which case my thought woundn't have worked...
@Calguy... have you seen this post?
Blogs and links I only ask as I thought your the author for that?
well cheers all
jeremyBass
Re: Displaying partial child content within parent page
Posted: Tue Dec 09, 2008 8:36 pm
by Weon
nhaack wrote:
IF NO EXTRA CONTENT BLOCKS -> Shortening text
Code: Select all
{content_dump start_id=$content_id exclude="$content_id" html="strip"}
{foreach from=$dump item=dump}
<h4>{$dump->content->title}</h4>
<span>{$dump->created->date}</span><br />
<p>{$dump->content->data|truncate:300}</p>
<a href="{$dump->content->alias}.htm">go to content page</a>
<hr />
{/foreach}
Let me know if that could do the trick for you.
Best
Nils
Hi Nils
I've been playing with your plugin and it does pretty much exactly what I need. There is just one thing though...
Is it possible to limit it to displaying direct child content only (i.e. not the children of children)? Looking at your documentation it looks like it's possible to exclude individual items but not to exclude/include individual levels in the hierarchy.
I'll keep playing but if you can help in the meantime it would be great.
Re: Displaying partial child content within parent page
Posted: Tue Dec 09, 2008 11:13 pm
by nhaack
Hi Weon,
unfortunatly, content_dump does not support level based collections at the moment. However, you are actually the second one to ask for the feature within a short time. I already planned this feature for the next version.
Beginning tomorrow, I start a month of holiday (have to get rid of all my free days

). Though I actually want to complete another private project of mine and go snow boarding, I consider a new version feasible somewhen near the end of january (probably earlier).
There are several work arounds at the moment. One involves other content blocks. It basically goes like this: add an extra content block to your template used on the specific hierarchy and tell content_dump to only go for this block. But this approach holds some downsides, you have more specific templates and the extra block you didn't want.
The other one is really dirty and involves using content_dump several times. On your main index template you call the plug-in for each sub-directory. With the smarty tag {capture} you then create a string of all IDs seperated by comma. You then use this string in the exclude parameter to call the last occurance of content_dump. You basically create a list of pages you don't want to have and tell this to the plug-in.
You might get lucky with a combination of the menu module to generate the exclude list and passing this to content_dump. I think that might also work.
However, if you do not have major urgence in your project, I suggest you wait a few weeks and get the feature directly with the plug-in without building things you need to get rid of afterwards - concentrate on the design or other site features in the meantime
Or check calguy's solution. I am not familiar with it, but I guess something like that could be possible... Calguy, can you say more?
Best
Nils
Re: Displaying partial child content within parent page
Posted: Wed Dec 10, 2008 8:58 am
by Weon
Firstly, thanks to all who have replied. Here is how I got to where I am now...
Having looked at the three solutions from Jeremy, Nils and CalGuy it seemed that the easiest and most promising was the
content_dump plugin from Nils. Bearing in mind that my deadline is pretty tight I needed to get this sorted ASAP.
Having installed it, I used it in the way that Nils directed and it worked a treat. The only downside is that I only wanted to display partial content of direct children but content_dump just pushes all the way down the hierarchy, listing everything it finds. While Nils has said there are workarounds, I don't really have time to play with it so sadly I had to ditch this option (although I am looking forward to version 0.7 that will probably have this functionality in

thanks Nils!)
So I turned my attention to Jeremy's suggestion, creating a UDT (User Defined Tag) that would pull out the information I required but using the Extra Page Attribute 1 field from the options for each page, rather than a truncated content block. I followed his instructions but it didn't work. Hmm. So I checked the code and checked it against CalGuy's and saw that it included a call to the
CGSimpleSmarty module. I downloaded and installed this and it worked as Jeremy said it would. Great.
However, I then thought "Well, now I've installed the module, I'll try the solution that CalGuy suggested as he said it was really simple" (really simple are two words I like!). So I copied and pasted the code but got a fatal error. I tried it a couple of times but it didn't work so I abandoned that pretty quickly.
So this brought me back to Jeremy's solution. I tried changing it to output a truncated version of the page content block but couldn't get it to work (I think I may have mentioned that my coding skills/knowledge aren't exactly legendary) so I am doing pretty much what he suggested in the first place!
So there you go, a long, roundabout way of coming back tot he first solution that was suggested! Thanks Jeremy.
P.S. For those that like that kind of thing, here is my final code:
Code: Select all
global $gCms;
$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['page_name'];
$currentNode = &$manager->sureGetNodeByAlias($thisPage);
$nodes = $currentNode->getChildren();
if ($currentNode->hasChildren()) {
foreach ($nodes as $node) {
$content= $node->getContent();
$page_alias = $content->Alias();
$cgsimple = $smarty->get_template_vars('cgsimple');
$Sum = $cgsimple->get_page_content($page_alias, 'extra1');
$url = $content->GetURL();
if ($url == "#") { /* section header has no link by default */
$url = "index.php?page=".$content->Alias();
}
echo "<h3><a href=\"".$url."\" title=\"".$content->TitleAttribute()."\">".$content->MenuText()."</a></h3>\n";
echo "<p>".$Sum." <a href=\"".$url."\" title=\"".$content->TitleAttribute()."\">[read more...]</a></p>\n";
}
Re: [Solved] Displaying partial child content within parent page
Posted: Wed Dec 10, 2008 3:22 pm
by JeremyBASS
I'm glad I could help... I'm sorry I forgot to say that you'd need calguys CGSimpleSmarty installed...

I install that and more right off the bat so I sometimes forget... I'd bet

that you could set what I layed out to aim for the content instead of the extra1...
so aim this at the content
$Sum = $cgsimple->get_page_content($page_alias, 'extra1');
then use the
{$Sum|truncate:300}
have a great day
jeremyBass
Re: [Solved] Displaying partial child content within parent page
Posted: Wed Dec 10, 2008 3:32 pm
by Weon
Ha ha! I might have a play with that if I have time. Just trying to get about 3 sites done and live before Christmas (or my nervous breakdown - whichever comes first really!)
I assume you mean
$Sum = $cgsimple->get_page_content($page_alias, '
content');
rather than
$Sum = $cgsimple->get_page_content($page_alias, '
extra1');
And then could I strip tags and truncate at the same time using
{$Sum|
strip_tags|truncate:300}
Must. Stop. Fettling.
Re: [Solved] Displaying partial child content within parent page
Posted: Wed Dec 10, 2008 7:47 pm
by JeremyBASS
I havn't looked in to it to see if
$Sum = $cgsimple->get_page_content($page_alias, 'content');
would work... but thats the idea... if it's not 'content' it can be grab some other way...
I hear ya on the many site not enough time... I have 3 due by firday... what today..

lol
laters
jeremyBass