Download the PHP package adunblock/server-tag-symfony without Composer
On this page you can find all versions of the php package adunblock/server-tag-symfony. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download adunblock/server-tag-symfony
More information about adunblock/server-tag-symfony
Files in adunblock/server-tag-symfony
Package server-tag-symfony
Short Description A Symfony bundle to fetch and render scripts from a remote URL with Twig integration and caching support.
License ISC
Homepage https://github.com/adunblock/adunblock-server-tag
Informations about the package server-tag-symfony
Server Tag Symfony Bundle
A Symfony bundle to fetch and render scripts from a remote URL with Twig integration and caching support. Perfect for server-side script loading and integration with third-party services.
Features
- Twig Integration: Easy-to-use Twig function for templates
- HTTP Client: Uses Symfony's HTTP client for reliable requests
- Caching: Built-in caching support with configurable TTL
- Error Handling: Graceful error handling with fallback to empty arrays
- Security: XSS protection with proper HTML escaping
- Bundle Structure: Proper Symfony bundle with dependency injection
- Wide Compatibility: Support for Symfony 5, 6, 7, and 8
Requirements
- PHP 7.4 or higher
- Symfony 5.x, 6.x, 7.x, or 8.x
- Twig 2.x or 3.x
Installation
Install the bundle via Composer:
Enable the bundle in your config/bundles.php:
Usage
Basic Usage
In your Twig template, use the server_tag() function to fetch and render scripts from a remote URL:
With Caching
Specify a cache duration (in seconds) as the second parameter:
This will cache the fetched scripts for 5 minutes (300 seconds), reducing external requests.
Custom Rendering
You can provide a custom callable as the third parameter to control how script tags are rendered:
Create a custom renderer service in your Symfony application:
Function Signature
Parameters:
$url(string): The remote URL to fetch scripts from$cache_seconds(int, optional): Cache duration in seconds. Default is 0 (no caching)$render_script(callable, optional): Custom rendering function. Receives an array of script URLs and returns an HTML string
How It Works
- The Twig function fetches content from the specified remote URL using Symfony's HTTP client
- If caching is enabled, the response is stored in Symfony's cache for the specified duration
- The fetched scripts are rendered as
<script>tags (or using your custom renderer) - The HTML is returned with proper XSS protection and can be used directly in your Twig templates
License
ISC
Support
- Issues: GitHub Issues
- Homepage: https://github.com/adunblock/adunblock-server-tag
Author
AdUnblock - [email protected]
All versions of server-tag-symfony with dependencies
symfony/http-client Version ^5.0|^6.0|^7.0|^8.0
symfony/cache Version ^5.0|^6.0|^7.0|^8.0
symfony/dependency-injection Version ^5.0|^6.0|^7.0|^8.0
symfony/http-kernel Version ^5.0|^6.0|^7.0|^8.0
twig/twig Version ^2.0|^3.0