Download the PHP package yohns/legal-pages without Composer
On this page you can find all versions of the php package yohns/legal-pages. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yohns/legal-pages
More information about yohns/legal-pages
Files in yohns/legal-pages
Package legal-pages
Short Description Generate customizable legal pages (Privacy Policy, Terms of Service, etc.) from Markdown templates with placeholder substitution — outputs Markdown or Bootstrap 5.3.8 HTML
License MIT
Informations about the package legal-pages
yohns/legal-pages
Generate customizable legal pages (Privacy Policy, Terms of Service, etc.) from Markdown templates with placeholder substitution — outputs Markdown or Bootstrap 5.3.8 HTML.
Getting Started
1. Install via Composer:
2. Publish starter files:
This copies a config file, a quickstart script, and an optional web UI into a legal-pages/ directory in your project root.
3. Edit your config and generate:
Output files (Markdown + Bootstrap HTML) are saved to legal-pages/generated/.
Publish Options
Programmatic Usage
Output Formats
Markdown (generate())
Returns raw Markdown with all placeholders replaced and conditional sections processed.
Bootstrap HTML Fragment (convertToHtml())
Returns HTML with Bootstrap 5.3.8 CSS classes on elements. No <html>, <head>, or <body> tags — just the content ready to embed in your existing page.
Bootstrap classes applied:
| Element | Classes |
|---|---|
<h1> - <h6> |
mb-3 |
<p> |
mb-2 |
<table> |
table table-striped |
<ul>, <ol> |
ps-3 |
<blockquote> |
blockquote ps-3 border-start border-4 |
<a> |
link-primary |
<hr> |
my-4 |
Full HTML Page (convertToHtml(full: true))
Returns a complete HTML document with the Bootstrap 5.3.8 CDN stylesheet included. Ready to save and open in a browser.
The page title is derived from the page type (e.g., privacy-policy becomes Privacy Policy).
Saving Files (savePage())
Save generated content to any directory. The directory is created automatically if it doesn't exist.
Parameters:
$content— The generated content (markdown or HTML)$filename— Output filename (sanitized withbasename())$outputDir— Directory to save to (created if missing)
Available Templates
Base Templates (all website types)
| Page Type | Template File |
|---|---|
privacy-policy |
legal/base/privacy-policy.md |
terms-of-service |
legal/base/terms-of-service.md |
cookie-policy |
legal/base/cookie-policy.md |
dmca-policy |
legal/base/dmca-policy.md |
accessibility-statement |
legal/base/accessibility-statement.md |
Website-Specific Templates
| Website Type | Template |
|---|---|
personal |
legal/personal/blog-disclaimer.md |
ecommerce |
legal/ecommerce/refund-policy.md |
ecommerce |
legal/ecommerce/shipping-policy.md |
social |
legal/social/content-policy.md |
Template resolution order:
legal/{websiteType}/{pageType}.md(website-specific)legal/base/{pageType}.md(fallback)
List Available Templates
Website Types
Pass the website type as the second constructor parameter:
The website type controls:
- Which templates are available (e.g.,
refund-policyonly for ecommerce) - Which conditional sections appear (
{{if:ecommerce}}...{{endif}})
Placeholders
Templates use {{category:field}} syntax. Pass values via the constructor or setter methods.
Via Constructor (nested array)
Via Constructor (flat format)
Via Setter Methods
Auto-Populated Placeholders
When yohns/config is configured with config/config.php, these placeholders are filled automatically:
| Placeholder | Config Key |
|---|---|
company:name |
company_name |
company:address |
company_address |
company:email |
contact_email |
company:phone |
contact_phone |
company:country |
company_country |
website:url |
site_url |
website:name |
site_name |
current:date |
Auto (today) |
current:year |
Auto (this year) |
Common Placeholder Categories
| Category | Fields |
|---|---|
company |
name, legal_name, email, phone, address, city, state, zip, country |
website |
url, name, domain |
data |
collected, cookies, retention, sharing, location |
compliance |
gdpr, ccpa, coppa, ada, dpa_email |
feature |
newsletter, analytics, medical_content, legal_content |
ecommerce |
payment_processors, shipping_providers, return_period, shipping_time, refund_time |
social |
content_policy, minimum_age, reporting, account_termination, content_rights |
See legal/placeholders/cheat-sheet.md for the complete reference.
Conditional Sections
Templates support conditional blocks based on website type or feature/compliance flags:
Enable compliance flags via placeholders:
Custom Template Directory
By default, templates are loaded from legal/ relative to the package root. Pass a custom path as the 4th constructor parameter:
Your custom directory should follow the same structure:
Config Integration
This package uses yohns/config to auto-load site defaults. Set up your config files:
config/config.php — Core site/company values (loaded first, available to other configs):
config/legal-pages.php — Legal-specific defaults, compliance flags, and page-specific placeholders:
These values are automatically used as placeholder defaults. Values passed to the constructor override config values.
Using Content Without Saving Files
You can use the generator to get content directly as PHP variables without writing any files. This is useful when you want to embed legal pages in your own templates, serve them dynamically, or store them in a database.
To generate multiple pages without saving files, set $outputDir to false and collect the results:
Full Example: Generate All Legal Pages
Testing
License
MIT