Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Latest titles from blog section to appear in blog div on template

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 1961 Views
  • lusiton
    Avatar
    13 Posts

    Latest titles from blog section to appear in blog div on template Link to this post

    Hello Guys.
    I previously used CMS system called Mephisto that run on Ruby on Rails. I'm looking for similar functions with SS and not sure I can figure it out. What I need is:
    Latest article titles from section to appear on the template in separate div. For instance three latest titles from the blog section to appear in blog div on template.
    I'm sure there is a way to do it. I'm just stupid and can't figure it.

    Thank you in advance.

  • Tim
    Avatar
    Core Development Team
    201 Posts

    Re: Latest titles from blog section to appear in blog div on template Link to this post

    Tutorial two will take you through doing this, however as a really simple example on how to do this you could use

    <% control ChildrenOf(latest-news) %>

    <h2>$Title</h2>
    $Content.LimitWordCount(50)
    <a href=$Link> more </a>

    <% end_control %>

    This would assume you have a page with the URL "latest-news", and you want to loop though all it's children, display a summary of the first 50 words, and then provide a link to the main article.

    Just put this code anywhere in your tempalte

  • lusiton
    Avatar
    13 Posts

    Re: Latest titles from blog section to appear in blog div on template Link to this post

    Hi Tim.

    I appreciate your help on this.
    I'm going to try it.

    Thank you.

  • lusiton
    Avatar
    13 Posts

    Re: Latest titles from blog section to appear in blog div on template Link to this post

    I got it working. Now I'm trying to figure out to do the same with the blog page so it will display few of the blog children. This is what I came up with:

    <div id="blog">
    <% if blog %>
    <p class="ChildrenOf(blog)">
    <% $Content.LimitWordCount(20) %>
    <h3>$Title</h3>
    <a href="$Link"> more </a></p>
    <% end_if %>
    </div>

    So far no luck but probably I'm doing something wrong again. Also some how I want to limit the number of children instances on the page. If you have ideas it would be great. I'm trying to learn from my mistakes.

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Latest titles from blog section to appear in blog div on template Link to this post

    if you are on the blog page template and want to control its children you can just use <% control Children %>

  • lusiton
    Avatar
    13 Posts

    Re: Latest titles from blog section to appear in blog div on template Link to this post

    Hello Willr.

    Thank you for responding to my post.
    So far I have single template to accommodate my website and I'm not sure hot to add a separate template for particular section. In the main content section I have this code:
    $Content $Form $PageComments. If I will add this code <% control Children %> as you suggested it will control children of all sections unless it is on the separate template. It would be great if you could suggest how to assign a separate template to a section.

    Thank you in advance.

    1961 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.