Created
November 6, 2012 10:32
-
-
Save serapheem/4023927 to your computer and use it in GitHub Desktop.
Symfony2 - Linking to Assets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Twig: | |
<img src="{{ asset('images/logo.png') }}" alt="Symfony!" /> | |
<link href="{{ asset('css/blog.css') }}" rel="stylesheet" type="text/css" /> | |
PHP: | |
<img src="<?php echo $view['assets']->getUrl('images/logo.png') ?>" alt="Symfony!" /> | |
<link href="<?php echo $view['assets']->getUrl('css/blog.css') ?>" rel="stylesheet" type="text/css" /> | |
Working instance: | |
{# 'app/Resources/views/base.html.twig' #} | |
<html> | |
<head> | |
{# ... #} | |
{% block stylesheets %} | |
<link href="{{ asset('/css/main.css') }}" type="text/css" rel="stylesheet" /> | |
{% endblock %} | |
</head> | |
<body> | |
{# ... #} | |
{% block javascripts %} | |
<script src="{{ asset('/js/main.js') }}" type="text/javascript"></script> | |
{% endblock %} | |
</body> | |
</html> | |
{# src/Acme/DemoBundle/Resources/views/Contact/contact.html.twig #} | |
{% extends '::base.html.twig' %} | |
{% block stylesheets %} | |
{{ parent() }} | |
<link href="{{ asset('/css/contact.css') }}" type="text/css" rel="stylesheet" /> | |
{% endblock %} | |
{# ... #} | |
Include assets from the bundles: | |
<link href="{{ asset('bundles/acmedemo/css/contact.css') }}" type="text/css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment