component_resolve
host callCapy
function component_resolve(name : string) string
Description
component_resolve() answers "which file would component() actually load for this name?". It renders nothing and runs no handler.
This is the tool for debugging resolution. Because a relative name is tried against several directories in turn, the same string can mean different files depending on which unit is calling it, and the failure that follows is usually reported against the wrong place. Printing the resolved path shows you which candidate won.
The order it searches
.capy is appended when the name has no suffix. A :HANDLER suffix does not affect the returned path.
A name starting with / is tried as a real filesystem path first, then as a path under the site root.
A relative name is tried against, in order:
the directory of the entry unit handling the request
the directory of the unit calling
component_resolve(), when that differsthe site root
The first candidate that exists is returned. A candidate that resolves outside the site root is rejected, and the result is an empty string.
An empty return means that no component source file matches the name.
Check whether a component exists
if component_resolve(...) is a compile error. A string has no bool constructor.
Use this test:
if length(component_resolve(name)) > 0 { ... }
Parameters
name : a component path, optionally followed by :HANDLER
Return Values
The absolute source path the name resolves to, or an empty string when nothing matches.
Example
Capy
print(component_resolve("/doc/examples/card"), "\n")
Example
Capy
var resolved := component_resolve("card")
if length(resolved) > 0 { print(resolved, "\n") } else { print("unresolved\n") }
Example
Capy
print(component_resolve("/doc/examples/card.capy:CARD"), "\n")