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

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Twig ใน symfony 2 : "asset_url" include CSS/image/js

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

by thatsawan » 15/04/2015 2:54 pm

อีกหนึ่งวิธีที่สามารถ 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 551 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 551 times

Top