Problem/Motivation
When ESI blocks are called, we cannot know which page call the block.
In case a block needs a context, like the current node displayed, we cannot get it from ESI block.
Steps to reproduce
Add a block which load a node from current route and display node title. Configure block to be loaded with ESI.
We cannot get current node from ESI block.
Proposed resolution
Give current path or route when ESI url is called
Issue fork adv_varnish-3455470
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
shumer commentedСurrent page path can be passed as an additional query parameter in the ESI URL. The ESIBlockController would then read it and set up the route context accordingly.
However, this must not be the default behavior. Adding the page path to every ESI URL means Varnish caches the same block separately for every page, defeating the purpose of ESI for blocks that don't depend on page context (menus, sidebars, user blocks, etc.).
We can make a slightly diff approach:
1. Add a "Context-aware" checkbox to the ESI block configuration (next to the existing ESI/cachemode/TTL settings)
2. When enabled, _adv_varnish_build_esi_block() passes the current path as a query parameter (e.g. &context_path=/node/42)
3. ESIBlockController::content() reads context_path, resolves the route, and pushes it onto the route match so block plugins see the correct context
4. No VCL changes needed, Varnish already caches by full URL including query string
This keeps cache efficiency for context-independent blocks while enabling page-aware ESI for blocks that need it
Comment #5
shumer commentedComment #6
shumer commentedCode style issues fixed, testing coverage added. PR ready for review/validation.