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.

Template Questions /

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

customising content in your templates


Go to End


3 Posts   2466 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, 135 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! :)