All Projects → AlexandreKilian → craft-react

AlexandreKilian / craft-react

Licence: MIT, MIT licenses found Licenses found MIT LICENSE MIT LICENCE.md
Client and Server-side React rendering for CraftCMS

Programming Languages

PHP
23972 projects - #3 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to craft-react

craft-entry-instructions
A simple fieldtype to add instructions.
Stars: ✭ 16 (-60%)
Mutual labels:  craftcms, craft-plugin, craftcms-plugin, craft3
craft-audit
Audit log for Craft 3
Stars: ✭ 18 (-55%)
Mutual labels:  craftcms, craft-plugin, craftcms-plugin, craft3
tablemaker
A user-definable table field type for Craft CMS
Stars: ✭ 39 (-2.5%)
Mutual labels:  craftcms, craft-plugin, craftcms-plugin, craft3
Simplemap
A beautifully simple map field type for Craft CMS.
Stars: ✭ 136 (+240%)
Mutual labels:  craftcms, craft-plugin, craft3
craft3-forms
This craft CMS 3 form plugin makes it easy to create and use custom forms with the features the Yii 2 Framework offers. On top of this, the plugin provides even more functionalities for easy implementation of forms in twig templates.
Stars: ✭ 20 (-50%)
Mutual labels:  craftcms, craft-plugin, craft3
Craft Preparse Field
Field type that parses twig when an element is saved.
Stars: ✭ 103 (+157.5%)
Mutual labels:  craftcms, craft-plugin, craft3
Upper
Integrates Edge Caches like Fastly, KeyCDN, Cloudflare and Varnish with Craft.
Stars: ✭ 89 (+122.5%)
Mutual labels:  craftcms, craft-plugin, craft3
Craft Imageoptimize
Automatically create & optimize responsive image transforms, using either native Craft transforms or a service like Imgix, with zero template changes.
Stars: ✭ 227 (+467.5%)
Mutual labels:  craftcms, craft-plugin, craft3
Commerce
Fully integrated ecommerce for Craft CMS
Stars: ✭ 144 (+260%)
Mutual labels:  craftcms, craft-plugin, craft3
craft3-collections
Clean up those complex templates with Laravel Collections
Stars: ✭ 24 (-40%)
Mutual labels:  craftcms, craftcms-plugin, craft3
smartdown.craft-plugin
Bringing the unbridled joy of Markdown Extra and Smartypants to your Craft websites.
Stars: ✭ 26 (-35%)
Mutual labels:  craftcms, craft-plugin, craftcms-plugin
Craft-User-Manual
📚 Help Section Plugin for Craft CMS.
Stars: ✭ 86 (+115%)
Mutual labels:  craftcms, craft-plugin, craftcms-plugin
craft-router
A Craft CMS plugin for using URL segments as filtering criteria on an entry query.
Stars: ✭ 21 (-47.5%)
Mutual labels:  craftcms, craft-plugin, craft3
Guest Entries
Accept anonymous entry submissions with Craft.
Stars: ✭ 100 (+150%)
Mutual labels:  craftcms, craft-plugin, craft3
Plugins
The master list of Craft 3-compatible plugins
Stars: ✭ 111 (+177.5%)
Mutual labels:  craftcms, craft-plugin, craft3
Buttonbox
A collection of utility field types for Craft
Stars: ✭ 94 (+135%)
Mutual labels:  craftcms, craft-plugin, craft3
Seo
SEO utilities including a unique field type, sitemap & redirect manager
Stars: ✭ 210 (+425%)
Mutual labels:  craftcms, craft-plugin, craft3
craft-cookies
A simple plugin for setting and getting cookies from within Craft CMS templates.
Stars: ✭ 36 (-10%)
Mutual labels:  craftcms, craft-plugin, craft3
Aws S3
Amazon S3 volume type for Craft CMS
Stars: ✭ 57 (+42.5%)
Mutual labels:  craftcms, craft-plugin, craft3
Generator Craftplugin
generator-craftplugin is a Yeoman generator for Craft CMS plugins
Stars: ✭ 69 (+72.5%)
Mutual labels:  craftcms, craft-plugin, craft3

Craft React

Craft CMS React Renderer lets you implement React.js client and server-side rendering in your Craft CMS projects.

It is an implementation of ReactBundle for CraftCMS. For a complete documentation of the core functionality and client examples, as well as problems related to the Renderer itself, please check out ReactBundle or Symfony React Sandbox.

Why Server-Side rendering?

By rendering your react components on the server, you not only increase performance and search engine readability for SEO but also enable users with slower connections to be able to access your information before your client bundle has completely loaded.

How it works

Please checkout the Walkthrough for a step by step explanation of the client and twig-side of this plugin. For a JSON-API, we recommend Elements API for Craft CMS.

Installation

To install the plugin, follow these instructions:

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require alexk/craft-react
    

In the Control Panel, go to Settings → Plugins and click the “Install” button for Craft React.

Setup

In the plugin settings, add the following entries:

Environment: "client_side", "server_side" or "both"

Server Bundle: "PATH_TO_SERVER_BUNDLE"

or override the settings globally in config/react.php

<?php

return [
    'env' => 'client_side',
    'serverBundle' => 'app/server-bundle.js',
];

In your template, add the following TWIG-function where you want your react application to be rendered into:

    {{ react_component('MyApp', {'props': {entry: entry}}) }}

In the props, pass whatever props you want to pass to your root component.

Serialization

In order to serialize your entries to create a store or props, the new twig function serialize(entry, schema = 'entry', group = 'default') has been introduced. This allows you to create a php file to serialize your entries. Files should be located in config/react and should be named [schema].php. If unspecified, the schema will default to entry.php and the group to default.

<?php
# config/react/entry.php

use craft\elements\Entry;

return [
    'default' => function(Entry $entry){// named after the group
        return [
            'id' => $entry->id,
            'title' => $entry->title,
            'customField' => $entry->customField,
         ];
    }
];

To use it in twig, just pass your current entry and use the result in your store:

{# _entry.twig #}

{% set serializedBlogPost = serialize(entry,'blog', 'detail') %}
{{ react_component('MyApp', {'props': {blogpost: serializedBlogPost}}) }}

This will use the file config/react/blog.php

<?php
# config/react/blog.php

use craft\elements\Entry;

return [
    'detail' => function(Entry $entry){
        return [
            'id' => $entry->id,
            'title' => $entry->title,
            'content' => $entry->content,// custom field
         ];
    }
];
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].