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. It does not compile the file or check whether COMPONENT:NAME exists. A nonempty result can still name a file with a missing handler or a compile error.
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
Within each directory, Bearer also tries a components/ subdirectory for names that do not already start with components/. It tries the supplied name and its .capy form. The first candidate that exists is returned. Normal application targets must stay inside the site tree.
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:
var name := "/doc/examples/card.capy"
if length(component_resolve(name)) > 0
{
print("component found\n")
}
else
{
print("component missing\n")
}Output
component foundParameters
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")
Output
/work/site/doc/examples/card.capy
Example
Capy
var resolved := component_resolve("card")
if length(resolved) > 0 { print(resolved, "\n") } else { print("unresolved\n") }
Output
unresolved
Example
Capy
print(component_resolve("/doc/examples/card.capy:CARD"), "\n")
Output
/work/site/doc/examples/card.capy