Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Template tags in a page content field

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: 1570 Views
  • Trym
    Avatar
    Community Member
    18 Posts

    Template tags in a page content field Link to this post

    I have a single page in the cms of type Page where I would like to have a list of the pages children. If it had its own Layout template then I would write something like

    <ul id="NewsList">
    <% control Children %>
    <li class="newsSummary">$Content.FirstParagraph <a href="$Link" title="Read more on &quot;{$Title}&quot;">Read more &gt;&gt;</a></li>
    <% end_control %>
    </ul>


    but this gets encoded in the page content editor and rendered as html instead of a template tag.

    1. Is there any other way to get a dynamic list in the page other than having a special template.
    2. And if the only way is to have a special template, is there any way to define on a single page of type Page which template to use.

    Any comments are welcome and appreciated.

    Thanks
    Trym

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Template tags in a page content field Link to this post

    try with adding the following code

    <% control Menu(1) %>
    <ul id="NewsList">
    <% control Children %>
    <li class="newsSummary">$Content.FirstParagraph <a href="$Link" title="Read more on &quot;{$Title}&quot;">Read more &gt;&gt;</a></li>
    <% end_control %>
    </ul>
    <% end_control %>

  • Trym
    Avatar
    Community Member
    18 Posts

    Re: Template tags in a page content field Link to this post

    Thanks Nivanka.

    I probably didn't state my question very clear. I have a page of type Page. This single page I want to contain a dynamic list. I dont think it is possible to embed anything in the content-fields html and I havn't seen any examples of specifying which template a single page should use.

    I was thinking about extending silverstripe rendering, so it could choose which template to render the page in from the value of an attribut of the Page (extending the page),
    or attach another page to every page. And to this single page attach a page containing the dynamic list.

    Have anyone thought about this and choosen a generic solution to the problem?

    Best regards Trym

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Template tags in a page content field Link to this post

    If it is from an attribute of the page, you could user renderWith():

    class MyPage extends Page {
    static $db = array(
    'Template' => 'Varchar(50)'
    );
    }
    class MyPage_Controller extends Page_Controller {
    function init(){
    parent::init();
    }
    function index() {
    if($this->Template) {
    return $this->renderWith($this->Template);
    } else {
    return array();
    }
    }
    }

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Template tags in a page content field Link to this post

    Hmm this is a wee bit complex. To embed this sort of function. 1 method is to use tokens in the content - http://doc.silverstripe.com/doku.php?id=recipes:customising-content-in-your-templates but not too sure how you could get a list of pages outputed nicely (I can think of ugly ways!)

    That way could be 1 way (Your Paypal() function from that example would instead output a list of pages. It would be HTML in the PHP but it would work).

    1570 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.