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.

Template Questions /

customising content in your templates


Reply


3 Posts   1473 Views

Avatar
dataforlife

Community Member, 10 Posts

19 May 2010 at 7:41am

Edited: 19/05/2010 11:21pm

Hallo,

i have a question to the http://doc.silverstripe.org/recipes:customising-content-in-your-templates

This way i can use only one introduction, right? How can i use several introdutions?

for examlpe 2:

$Paypal for paypal.ss and $Pictures for pictures.ss

function Content() {
   
      $replace = "";
      $replace .= str_replace('$Paypal', $this->PaypalButton(), $this->Content);
      $replace .= str_replace('$Pictures, $this->Pictures(), $this->Content);

    return $replace;
   }

function PaypalButton() {
    return $this->renderWith("paypal");
   }

function Pictures() {
    return $this->renderWith("pictures");
   }

By this way the content of every page is shown twice. How can i do that right way?

Thanks a lot!

Avatar
3dgoo

Community Member, 133 Posts

25 May 2010 at 12:58pm

The problem is you're concatenating content into the replace string twice.
What you want to do is:

function Content() {

$replace = $this->Content;
$replace = str_replace('$Paypal', $this->PaypalButton(), $replace);
$replace = str_replace('$Pictures, $this->Pictures(), $replace);

return $replace;
}

Give that a go.

Avatar
dataforlife

Community Member, 10 Posts

29 May 2010 at 3:51am

THANK YOU! Thats it! :)