Hi
I know how to get variables from a template, but how to I get all bookmarks and fields ?
Thanks
Steen
Hi
I know how to get variables from a template, but how to I get all bookmarks and fields ?
Thanks
Steen
Hello,
You can use getDocxPathQueryInfo available in DOCXPath (https://www.phpdocx.com/documentation/introduction/docxpath) to query elements and extract information from them.
Regards.
I'm sure that I'm doing wrong, but in my case it does not work
I have a document with 2 bookmarks ( sorry, cannot insert image og doc)
$docx = new CreateDocxFromTemplate(storage_path('bookmark.docx'));
try {
return $docx->getDocxPathQueryInfo([
'type' => 'bookmark'
]);
} catch (\Exception $e) {
Log::error($e->getMessage());
}
result
array:3 [â–¼
"elements" => DOMNodeList {#2358 â–¼
+length: 0
}
"length" => 0
"query" => "//w:body/w:bookmarkStart[1=1]"
]
Hello,
Please note the following option available when using DOCXPath methods:
parent string Main document body as default, allows to set any parent or a specific one. w:body (default), '/' (any parent) or any other specific parent (/w:tbl/, /w:tc/, /w:r/...).
As default, the query is done only to direct children of the main tag (w:body). If you want to get all bookmarks, this is with any parent, you need to set parent to '/'. For example:
$docx->getDocxPathQueryInfo([
'type' => 'bookmark',
'parent' => '/',
]);
Also note that in a DOCX, a bookmark is a single tag without other contents. To extract fields using getDocxPathQueryInfo you may need to do a custom DOCXPath query. If you send a sample DOCX to contact[@]phpdocx.com we can generate a sample script to illustrate it.
Regards.