Skip to content

Instantly share code, notes, and snippets.

@slackday
Last active April 11, 2022 14:32
Show Gist options
  • Save slackday/2da504eb4728df727ce4b6aa49a3b2ca to your computer and use it in GitHub Desktop.
Save slackday/2da504eb4728df727ce4b6aa49a3b2ca to your computer and use it in GitHub Desktop.
Fix for loading Ninja forms preview in Sage theme version 10
<?php
namespace App;
/**
* Set preview page for ninja forms
*/
add_filter('template_include', function ($template) {
if (substr($template, -9) === 'index.php') {
$ninja_forms_id = isset($_GET['nf_preview_form']) ? $_GET['nf_preview_form'] : null;
if ($ninja_forms_id) {
$blade_template = locate_template('resources/views/ninja-forms-preview.blade.php');
return ($blade_template) ? $blade_template : $template;
}
}
return $template;
});
@extends('layouts.app')
@section('content')
@while(have_posts())
@php
the_post();
$ninja_forms_id = isset($_GET['nf_preview_form']) ? $_GET['nf_preview_form'] : null;
@endphp
<article class="container mx-auto mb-8">
<div class="px-5 mt-8 md:my-16 xl:mt-20">
<div class="max-w-screen-md mx-auto">
@if ($ninja_forms_id)
{!! do_shortcode("[ninja_form id=$ninja_forms_id]") !!}
@endif
</div>
</div>
</article>
@endwhile
@endsection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment