-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include local images #11
Comments
Hi! When I use If you assets reside outside of class SomeController extends AbstractController
{
public function someAction()
{
$filePath = '/my/path/outside_my_project_root/';
return $this->render('some/template.html.twig', ['filePath' => $filePath]);
}
} <img src="{{ filePath }}img.jpg" alt="My img"> Or even better, write a service/twig extension that elaborate the full path for you: namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class FileExtension extends AbstractExtension
{
public function getFunctions()
{
return [
new TwigFunction('get_file_path', [$this, 'getFilePath']),
];
}
public function getFilePath($fileName)
{
return '/var/www/outside_my_project/' . $fileName;
}
} <img src="{{ get_file_path('img.jpg') }}" alt="my img"> |
Hello, I also bumped on this issue. As I understood, it comes from We solved it using this asset package config & asset function combination : framework:
assets:
packages:
pdf:
base_urls: 'file://%kernel.project_dir%/assets/' # "file://" protocol indication seems very important here <img src="{{ asset('path/to/your/img.jpg', 'pdf') }}" alt="img"/> {# path to image at "%kernel.project_dir%/assets/path/to/your/img.jpg" #} |
Hello,
As anyone managed to include local images to pdfs created by the bundle ? I have no luck using the
asset
helper function, I can only use URLs for myimg
src
attribute for now and got no luck loading images locally directly.Thank you !
The text was updated successfully, but these errors were encountered: