There is also an example that has posts in this format, which looks like some sort of eager loading but I can't find the entries() function in the code so it must be parsed into something with a different name.

You can't just paste this markdown into the WYSIWYG editor or the page will 500, so you probably have to create a special "home page" .twig file or perhaps a layout inside pyro.

Update 2

Doesn't look like you can put code into the database or the site will 500 with "Twig_Error_Syntax: Unknown "posts" tag" which I guess is a limitation of using a templating engine that works with files. I do wonder if the layouts for page "types" could be cached as .twig files in storage?

ryanthompson -
1 year ago

Ya the WYSIWYG might format some things kinda funny as a sanitary action (which results in 500 I assume in your case). I would never advise putting code into the editor. You can use grid to safely allow adding HTML to a page or even as a partial so the client never sees it. But a homepage page type would be another good option.

psaunders -
1 year ago

Ok so the entries( ) arguments are pretty much

entries("namespace","table")

And the system does cache layouts and code in the storage directory. For me I created a page type called "code" that has a field type that is a twig editor which i pasted the snipet of code from the top into and out came the errors:

So you can go to the file location /code.twig and edit it in a normal editor. I assume it gets overwritten by a database edit though. The error might be related to my layout which just has a {{ page.code }} tag in it, but I guess it's an object and it needs to be {{ page.code | render }} or something.

psaunders -
1 year ago

Which corespond to function names in the EditorFieldTypePresenter class. Seems that the .rendered() is deprecated so I'm going with .render.
That gives me:

Twig_Error_Syntax: Unknown "posts" tag in "/Users/admin/www/websitename/storage/streams/default/pages/home_page_pages/3/code.twig" at line 1. in /Users/admin/www/website/vendor/twig/twig/lib/Twig/Parser.php:181

I'm wondering if the code snippet can't just be placed in a page. If I put some HTML in the box it renders the content out as a quoted string with any of {{ page.code.content }} {{ page.code.render }} which is weird. The syntax is definately twig but I've never used it before so I'm giving up on that whole approach and going to look into routes.

psaunders -
1 year ago

So routes... It's not the routes/web.php file seeing as that still seems to be pointing at the laravel welcome page. So I'm looking around for a routes.php or web.php file first, and then I'm going to look for something that starts with

Route::get('/', 'Anomaly\PagesModule\Http\Controller\PagesController

Because something like that is currently being called to have the site in the state that it is currently in. Hopefully I can edit that location.
There's a PublishRoutes console command which looks like it generates a simple get request route to a "welcome" view and puts it in the resources folder. Apparently that didn't run during my setup. I created the file manually but that didn't seem to do anything.

psaunders -
1 year ago

Running vendor:publish CLI command did publish a few vendor files but they all seemed to be part of other Laravel packages. I found a class called IncludeRoutes which again tries to run the getResourcesPath('routes.php') so i thought I would do a dd() on that command and see where it is evaluating. It's not going to the resources directory, it's going to /resources/default/routes.php, that directory doesn't even exist. After manually creating the folder, file and putting in Ryan's code from above I have got a website with the posts module as the home page.

ryanthompson -
1 year ago

ryanthompson -
1 year ago

entries("namespace","stream_slug")

Is the proper syntax. Your error says you've got Twig syntax issue in there so paste that and we'll be set.

You're spot on on the render btw: {{ page.field_slug.render|raw }}. {{ page.field_slug|raw }} is the same thing but it uses __toString() magic to return render() which will hide errors since __toString() is not allowed to throw exceptions in PHP. So for best results use the .render|raw one.