Skip to content

phpconcur/twig-resource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TwigResource

Resource handling for Twig templates

Example Template

index.php

$loader = new Twig_Loader_Filesystem('/path/to/templates');
$twig = new Twig_Environment($loader);
$twig->addExtension ( new Concur\Resource\Twig () );
echo $twig->render('home.twig');

base.twig

<!DOCTYPE html>
<html lang="en">
<head>
{% resource CSS '/css/bootstrap.min.css' %}
{% resource CSS '/css/bootstrap-theme.min.css' %}
{% resource JS '/js/jquery.min.js' %}
{% resource JS '/js/bootstrap.min.js' %}

{% for c in ResourceList('CSS')  %}
  <link rel="stylesheet" type="text/css" href="{{ c.name }}" />
{% endfor %}  
</head>
<body>
{% block body %}
{% endblock %}

{% for s in ResourceList('JS') %}
  <script src="{{ s.name }}" ></script>
{% endfor %}
</body>
</html>

home.twig

{% extends "base.twig" %}
{% resource CSS '/css/home.css' %}
{% resource JS '/js/home.js' %}

{% block body %}
<div class="container">
  HOME PAGE
</div>
{% endblock %}

render

<!DOCTYPE html>
<html lang="en">
<head>
  <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css" />
  <link rel="stylesheet" type="text/css" href="/css/bootstrap-theme.min.css" />
  <link rel="stylesheet" type="text/css" href="/css/home.css" /> 
</head>
<body>
  <div class="container">
    HOME PAGE
  </div>

  <script src="/js/jquery.min.js" ></script>
  <script src="/js/bootstrap.min.js" ></script>
  <script src="/js/home.js" ></script>
</body>
</html>

About

Resource handling for Twig templates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages