whitecube / nova-flexible-content

Flexible Content & Repeater Fields for Laravel Nova
MIT License
787 stars 232 forks source link

Integration with whitecube/nova-page #319

Open nicholasscottfish opened 2 years ago

nicholasscottfish commented 2 years ago

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

    <p>Edited on <time datetime="2022-01-19T16:38:37+00:00">Jan 19, 2022</time></p>
    <p>All you need to know!</p>
    <p>[{"key":"hMkhMH5bJKdC8tpO","layout":"wysiwyg","attributes":{"title":"Sample Title","content":"Lorem ipsum"}},{"key":"9eoUojlRf4ylGGkN","layout":"video","attributes":{"title":"Video Title","video":"0984343","caption":"Sample caption"}}]</p>

Any help or pointers would be massively appreciated.

Thank you.

nickbluestone98 commented 2 years ago

Does this not print out your output?

<?php print_r(Page::flexible('content')) ?>

Take a look here: https://github.com/whitecube/nova-flexible-content#usage-with-nova-page