Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Template tags in a page content field


Go to End


5 Posts   2765 Views

Avatar
Trym

Community Member, 18 Posts

6 December 2008 at 12:51am

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

Avatar
Nivanka

Community Member, 400 Posts

7 December 2008 at 7:18pm

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 %>

Avatar
Trym

Community Member, 18 Posts

8 December 2008 at 10:11pm

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

Avatar
Hamish

Community Member, 712 Posts

11 December 2008 at 8:10am

Edited: 11/12/2008 8:10am

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();
    }
  }
}

Avatar
Willr

Forum Moderator, 5523 Posts

12 December 2008 at 5:33pm

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