| Recommend this page to a friend! |
| Info | Reputation | Support forum | Blog | Links |
| Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
| 2026-02-15 (7 days ago) | Not yet rated by the users | Total: Not yet counted | Not yet ranked | |||||
| Version | License | PHP version | Categories | |||
| linkgenerator 1.0.0 | Public Domain | 8 | HTML, Templates, PHP 8 |
| Description | Author | |
This package can generate HTML for links and forms from templates. |
StartDir\LinkGenerator is a template-driven URL and form generator.
Code formatting and documentation was created with the help of ChatGPT!
Get the latest Version here.
It allows you to:
Register URL templates per software and module
Generate links dynamically from placeholders
Automatically generate matching HTML forms
Validate that all placeholders are replaced
Separate URL structure from runtime values
The class is especially useful when generating search or action URLs for platforms such as Mastodon or Friendica, where URL patterns are predictable but instances differ.
Templates are stored as a two-dimensional array:
[
'software' => [
'module' => 'https://{instance}/path?q={q}'
]
]
Placeholders use {name} syntax.
Reserved placeholder:
{instance} → always replaced automatically
All other placeholders must be supplied via parameters (for links) or are converted into form fields (for forms).
public function __construct(array $defaultTemplates = [])
Allows optional default templates to be injected during instantiation.
$generator = new \StartDir\LinkGenerator([
'mastodon' => [
'search' => 'https://{instance}/search?q={query}'
]
]);
addTemplate()
public function addTemplate(
string $software,
string $module,
string $template
): void
Registers or overwrites a template.
Software names are normalized to lowercase.
Modules are case-sensitive.
$generator->addTemplate(
'friendica',
'search',
'https://{instance}/search?q={q}'
);
$generator = new \StartDir\LinkGenerator();
$generator->addDefaults();
if ($generator->templateExists('mastodon', 'search')) {
echo $generator->generateLink(
'mastodon.social',
'mastodon',
'search',
['q' => 'open source'],
);
echo $generator->getFormHtml(
'mastodon.social',
'mastodon',
'search',
'GET',
[
// 'q' => ''
],
[
'target'=>'_blank',
],
);
}
| The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
| Version Control | Unique User Downloads | |||||||
| 0% |
|
| Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.