Skip to content

Commit

Permalink
Add custom script doc to README
Browse files Browse the repository at this point in the history
  • Loading branch information
regisphilibert committed May 19, 2020
1 parent 2db11f0 commit 147be1a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,38 @@ fields:
label: "Title"
name: "title"
widget: "string"
```

## Scripts

The module faciliate the addiont of extra Netlify CMS scripts for WidgetPreviews, CollectionPreviews etc...

By default the module prints the content of any `assets/netlifycms.js` file found inside a `<script>` tag.

For more control, user should create its own `layouts/partials/tnd-netlifycms/scripts.html` partial and load the project's custom scripts there.

### Custom Scripts Partial example:

In this example, we use the load the project's stylesheet for the Articles previews and fire the Custom Preview afterwards, using the project's own classes.

```
{{ $style := false }}
{{ with resources.Get "css/style.css" }}
{{ $style = . | resources.PostCSS }}
{{ end }}
<script>
{{ with $style }}
CMS.registerPreviewStyle("{{ $style.Permalink }}");
{{ end }}
var PostPreview = createClass({
render: function() {
var entry = this.props.entry;
return h('div', {"className": "px-4"},
h('h1', {"className": "text-5xl font-normal pt-10 mb-16"}, entry.getIn(['data', 'title'])),
h('div', {"className": "my-4 user-content"}, this.props.widgetFor('body'))
);
}
});
CMS.registerPreviewTemplate("articles", PostPreview);
</script>
```

0 comments on commit 147be1a

Please sign in to comment.