processwire / processwire-requests

ProcessWire feature requests.
39 stars 0 forks source link

Documentation request: additional arguments for Page::render() #459

Closed teppokoivula closed 4 months ago

teppokoivula commented 1 year ago

Docs page for Page currently states that Page::render() accepts only one argument, which is the field name:

$page->render($fieldName = '') string mixed Returns rendered page markup. If given a $fieldName argument, it behaves same as the renderField() method.Can also be used as property: $page->render

Meanwhile the docs page for PageRender::renderPage() explains that you can also pass an array of custom variables in, and that this method actually accepts two arguments:

This method provides the implementation for $page->render() and you sould only call this method as render() from Page objects. You may optionally specify 1-2 arguments to the method. The first argument may be an array of options OR filename (string) to render. If specifying a filename in the first argument, you can optionally specify the $options array as the 2nd argument.


Additional confusion arises from the fact that according to Page docs Page::render() only accepts fieldname, while according to PageRender::renderPage() docs page it only accepts filename or options array.

I see that there's a "before" hook that changes the behaviour depending on whether the first argument looks like a field name, so PageRender::renderPage() docs page is not wrong, but it's still confusing when trying to figure out what Page::render() actually does/accepts (assuming that one has come this far in the first place) :)


... and finally, if a field name is passed as an argument to Page::render(), it actually accepts two arguments: field name and file name. Currently that behaviour doesn't seem to be documented.

ryancramerdesign commented 5 months ago

Thanks @teppokoivula those are good observations. I have pushed updates to the documentation for this to the dev branch, and it will appear in the live documentation once I update the ProcessWire version running the website.

teppokoivula commented 4 months ago

Thanks, Ryan!