nova-flexible-content icon indicating copy to clipboard operation
nova-flexible-content copied to clipboard

Integration with whitecube/nova-page

Open nicholasscottfish opened this issue 2 years ago • 1 comments

Hi there,

We have installed Nova Page and have set up an example page with a view that outputs the data as expected.

<h1>{{ Page::title() }}</h1>
<p>Edited on <time datetime="{{ Page::date('updated_at')->format('c') }}">{{ Page::date('updated_at')->toFormattedDateString() }}</time></p>
<p>{{ Page::get('subtitle') }}</p>

We have then installed nova-flexible-content and added a couple of flexible layouts:

    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            Text::make('Subtitle')
                ->sortable()
                ->rules('required', 'max:255'),

            Flexible::make('Content')
                ->addLayout('Simple content section', 'wysiwyg', [
                    Text::make('Title'),
                    Markdown::make('Content')
                ])
                ->addLayout('Video section', 'video', [
                    Text::make('Title'),
                    Text::make('Video ID (YouTube)', 'video'),
                    Text::make('Video Caption', 'caption')
                ]),
        ];
    }

We cannot figure out how to then access the flexible content, all we can get is the json. We have read the documentation about casting using the flexible() helper but cannot figure it out. Here is what we currently have:

<h1>{{ Page::title() }}</h1>
<p>Edited on <time datetime="{{ Page::date('updated_at')->format('c') }}">{{ Page::date('updated_at')->toFormattedDateString() }}</time></p>
<p>{{ Page::get('subtitle') }}</p>
<p>{{ Page::get('content') }}</p>

Output:

About Us

Edited on

All you need to know!

[{"key":"hMkhMH5bJKdC8tpO","layout":"wysiwyg","attributes":{"title":"Sample Title","content":"Lorem ipsum"}},{"key":"9eoUojlRf4ylGGkN","layout":"video","attributes":{"title":"Video Title","video":"0984343","caption":"Sample caption"}}]

Any help or pointers would be massively appreciated.

Thank you.

nicholasscottfish avatar Jan 19 '22 16:01 nicholasscottfish