picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.82k stars 616 forks source link

pico 2 pagetree recursion and twig #500

Closed marcus-at-localhost closed 5 years ago

marcus-at-localhost commented 5 years ago

Hi, after updating to v 2.0 I have trouble to deal with the pages and all the recursiveness.

before I was using something like this in my twig template:

<script>
    var current_page = {{ current_page | json_encode(constant('JSON_PRETTY_PRINT')) }};
</script>

but that is not possible anymore (it ends up in 1GB error log because of some array_walk_recursive() in twig) Is it because all leaves are added as &references? How to deal with this tree? - I read something about it here: http://picocms.org/in-depth/features/page-tree/ but it doesn't really apply.

Thanks.

PhrozenByte commented 5 years ago

Export just the variables you really need to JavaScript.

marcus-at-localhost commented 5 years ago

I can do that. Could you please give a hint/link what the idea behind this kind of tree is, that it consists of references and that it is ending in an infinit loop when using a recursive function? (In this case Twig). I'm curious, because I've never seen that before. Thank you!

PhrozenByte commented 5 years ago

The references are necessary to access the page tree array from the pages array and vice-versa. A page references its corresponding node in the page tree, and the node back-references its page. This back-reference is causing the infinite loop in many functions (including json_encode). For Pico 3.0 we're planning to replace both the pages array and the page tree array with objects, so that json_encode won't stumble over this anymore (that's not the primary goal of this change (it's for performance reasons), but it's a nice side-effect).

marcus-at-localhost commented 5 years ago

I'm looking forward to version 3!