Page 1 of 1

Twig ใน symfony 2 : "asset_url" include CSS/image/js

Posted: 15/04/2015 2:54 pm
by thatsawan
อีกหนึ่งวิธีที่สามารถ Include CSS / Image / JS คือ

Code: Select all

{% block stylesheet %}
    {% stylesheets 
    '@TestHelloBundle/Resources/public/css/menu.css' 
    '@TestHelloBundle/Resources/public/css/styles.css'%}
    <link href="{{ asset_url }}" rel="stylesheet" media="screen" />
    {% endstylesheets %}
มีขั้นตอนดังนี้
2015-04-15_14-49-54.png
2015-04-15_14-49-54.png (90.23 KiB) Viewed 550 times
เพื่อเป็นการ Cofig ตัวแปร นี้ ให้รู้ว่าเราจะใช้งาน Url ของ Controller ใหน ค่ะ

Code: Select all

{{ asset_url }}
[code]<!DOCTYPE html>
<html>
<head>
{% block stylesheet %}
{% stylesheets
'@TestHelloBundle/Resources/public/css/menu.css'
'@TestHelloBundle/Resources/public/css/styles.css'%}
<link href="{{ asset_url }}" rel="stylesheet" media="screen" />
{% endstylesheets %}
{% endblock %}

{% block javascript %}
<script src="{{ asset('bundles/TestHello/js/script.js') }}" type="text/javascript"></script>
{% endblock %}
<title>{% block title %}{{name}}{% endblock %}</title>
</head>
</head>
<body>
<div id='cssmenu'>
<ul>
<li><a href='#'><span>Home</span></a></li>
<li class='active has-sub'><a href='#'><span>Products</span></a>
<ul>
<li class='has-sub'><a href='#'><span>Product 1</span></a>
<ul>
<li><a href='#'><span>Sub Product</span></a></li>
<li class='last'><a href='#'><span>Sub Product</span></a></li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Product 2</span></a>
<ul>
<li><a href='#'><span>Sub Product</span></a></li>
<li class='last'><a href='#'><span>Sub Product</span></a></li>
</ul>
</li>
</ul>
</li>
<li><a href='#'><span>About</span></a></li>
<li class='last'><a href='#'><span>Contact</span></a></li>
</ul>
</div>
<div id="content">{% block content %} {% endblock %}</div>
<div id="sidebar">{% block sidebar %} {% endblock %}</div>
<div id="footer">
{% block footer %}
&copy; 2015 mindphp.com
{% endblock %}
</div>
</body>
</html>[/code]

ผลที่ได้
2015-04-15_14-46-43.png
2015-04-15_14-46-43.png (59.67 KiB) Viewed 550 times