Last active
September 2, 2015 03:48
-
-
Save ehyland/31a0501981b62eaab5a4 to your computer and use it in GitHub Desktop.
React Competent in SilverStripe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gist title |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var React = require('react/addons'); | |
var App = React.createClass({ | |
getInitialState: function() { | |
return { | |
data: window.ReactAppData | |
}; | |
}, | |
render: function() { | |
var data = this.state.data; | |
return ( | |
<div className="event-app"> | |
<h1>data.Title</h1> | |
<p>data.Content</p> | |
<div className="footer">data.FooterText</div> | |
</div> | |
); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyPage extends Page{ | |
private static $has_one = array( | |
'ReactComponent' => 'MyReactComponent' | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ReactComponent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyReactComponent extends Dataobject{ | |
private static $db = array( | |
'Title' => 'Varchar(255)', | |
'Content' => 'Varchar(255)', | |
'FooterText' => 'Varchar(255)' | |
); | |
private static $belongs_to = array( | |
'Parent' => 'MyPage.ReactComponent' | |
); | |
public function forTemplate(){ | |
Requirements::javascript("path/to/app.js"); | |
$output = "window.ReactAppData=".json_encode($this->toMap()); | |
$output .= "<div id=\"AppRoot\"></div>"; | |
return $output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment