sulu / SuluHeadlessBundle

Bundle that provides controllers and services for using Sulu as headless content management system
MIT License
45 stars 25 forks source link

Page does not exist in "html" format Exception is thrown for templates that are configuard as headless. #104

Closed mario-fehr closed 2 years ago

mario-fehr commented 2 years ago
Q A
Sulu Version 2.4.0
PHP Version 8.0.2
DB Version MySQL 8
Headless Bundle Version 0.6.2

Actual Behavior

If now twig file exist for the template the exception get thrown. image If the twig file exist for the template everthing is just fine. image

Expected Behavior

No need to create the twig template files if the template should be used as headless.

Steps to Reproduce

Here is a link to the demo repo with the bug.

alexander-schranz commented 2 years ago

@mfehr94 the exception is only thrown when you are not requesting the page with .json. When using the headless bundle you need to make sure that you request the json using /your-url.json. Without it requires a .html.twig as you are then requesting a html response. So this behavoiur is expected.

If you use javascript server side (Next.js, Nuxt, ...) rendered implementation all request to /your-url (without .json) should be handled by that serve and so never hit sulu itself. This is something you need to make sure in your VHost or server routing. Else if sulu provide the html where a client side application is started to communicate over with the headless bundle create one headless.html.twig which is used by every template which just starts your client javascript.

mario-fehr commented 2 years ago

@alexander-schranz thank you for the explanation. My mistake was I did not change the view property in the template xml files. So there are two ways of doing this. Use <view>base</view> or <view>pages/headless</view> if you want to use templates/pages/headless.html.twig