getgrav / getgrav/grav-plugin-shortcode-core

Add documentation on using debugger with admin plugin

Open
#60 0 comments 0 reactions 0 assignees View on GitHub
documentation
Dominant language
PHP
Stars
47
Forks
17
PR merge metrics
No merged PRs in 30d

Description

This took forever to figure out, so I'm hoping this issue can be a launching point for writing some documentation on a painful edge case I ran into when trying to build & debug a new shortcode extension. The TLDR is a docs that says something like this "for code running inside shortcode handler functions, to output debug information you should either return the log information as part of the shortcode handler return value, or you should use the grav log. Usage of the grav debugger will work in most situations, but log information will not be displayed inside the admin plugin"

Here's why (The following issue assumes all caching is turned off, so every request should re-trigger processing....)

When using the editor (at `/admin/pages/`) you are by default in the "Editor" mode. When you switch into the "Preview" mode, you can see the end result of your custom shortcode handler logic. However, if you have Grav debugger statements inside your shortcode handler function, they will not be displayed in the page's debugger log

The problem is that clicking "Preview" triggers a "processMarkdown" AJAX call to awaken grav and handle processing the markdown and by extension calling shortcode-core which will call your custom shortcode handler logic. _Processed content_ will be returned via the same AJAX call via the magic of the admin plugin, but the debugger log contents are not returned.

On a different note, I went down this rabbit hole of debugging because my shortcodes work fine on `/admin/preview/...` but do not work on `/admin/pages/...`. It currently seems some high level information is different between those two, e.g. the $page variable changes.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.