Added a randomiyed header image
This commit is contained in:
parent
a2f2fd7317
commit
e1037a1c55
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
@ -11,7 +11,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="content-wrapper">
|
||||
<div id="header">
|
||||
<div id="header" style="background-image: url('{{ asset('bundles/gergelypolonkaifront/images/' ~ random_header) }}');">
|
||||
<h1><a href="{{ path('GergelyPolonkaiFrontBundle_homepage') }}">Gergely Polonkai</a></h1>
|
||||
<h2>developer, systems engineer and administrator</h2>
|
||||
<div id="contact-list">
|
||||
|
54
src/GergelyPolonkai/FrontBundle/Twig/RandomHeader.php
Normal file
54
src/GergelyPolonkai/FrontBundle/Twig/RandomHeader.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace GergelyPolonkai\FrontBundle\Twig;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Description of RandomHeader
|
||||
*
|
||||
* @author polonkai.gergely
|
||||
*
|
||||
* @DI\Service
|
||||
* @DI\Tag("twig.extension")
|
||||
*/
|
||||
class RandomHeader extends \Twig_Extension
|
||||
{
|
||||
/**
|
||||
* @var string $rootDir
|
||||
*/
|
||||
private $rootDir;
|
||||
|
||||
/**
|
||||
* @DI\InjectParams({
|
||||
* "kernelRootDir" = @DI\Inject("%kernel.root_dir%")
|
||||
* })
|
||||
*/
|
||||
public function __construct($kernelRootDir)
|
||||
{
|
||||
$this->rootDir = $kernelRootDir;
|
||||
}
|
||||
|
||||
public function getGlobals()
|
||||
{
|
||||
return array(
|
||||
'random_header' => $this->randomHeader(),
|
||||
);
|
||||
}
|
||||
|
||||
private function randomHeader()
|
||||
{
|
||||
$dh = opendir($this->rootDir . '/../web/bundles/gergelypolonkaifront/images');
|
||||
$files = array();
|
||||
while ($fn = readdir($dh)) {
|
||||
if (preg_match('/^header_\d+\.png/', $fn)) {
|
||||
$files[] = $fn;
|
||||
}
|
||||
}
|
||||
return $files[array_rand($files)];
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return 'random_header';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user