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

Include PHP command in .ss


Go to End


3 Posts   2595 Views

Avatar
corkg

Community Member, 30 Posts

5 June 2008 at 11:58pm

How can you add a PHP Query in the Page.ss File?

if($HeaderImage == NULL){$HeaderImage=="imsa_files/construct/header.png"; }else{ $HeaderImage=="$HeaderImage";}

Where $HeaderImage is a Variable saved into the database.

Avatar
sammahoney

Community Member, 14 Posts

6 June 2008 at 12:58am

I've been asking the same thing but no joy so far. I want to add a PHP include to a .ss file, but I get an error everytime.

Anyone any ideas no?

Avatar
zyko

Community Member, 66 Posts

6 June 2008 at 1:53am

Edited: 06/06/2008 1:55am

corkg,

if 'Variable saved into the database' means a page db_column:
i know it's not absolutely the thing you want,
i do these things by implementing a function on the page (or DataObject)
which has this logic inside.
than use the function in the template

fe:

public function RealHeaderImage() {
  if (!$this->HeaderImage) {
    return "imsa_files/construct/header.png";
  }
  return $this->HeaderImage;
}

then in ss use

  $RealHeaderImage() 

not sure whether soemeone has to use brackets, or not...

g
Helmut