Symfony2, Can't display calendar of adesigns CalendarBundle - symfony

I'm trying to display the calendar of adesigns CalendarBundle
https://github.com/adesigns/calendar-bundle
I followed the "Installation" and "Usage" parts, but nothing shows up
{% extends '::base.html.twig' %}
{% block title %}calendar{% endblock %}
{% block body %}
{% include 'ADesignsCalendarBundle::calendar.html.twig' %}
{% endblock %}
I don't know what to do, do I have to write something in the controller? create a bundle?

It works now
I added:
<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>

It's important about this problem the position of the links must be in the layout.html.twig or in this example in base.html.twig.
In the documentation the calendar-bundle only say the requirement of installation FOSJsRouting but they not say configuration this links is obligatory:
<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>
For this job I work with Symfony 3
Regards

Related

using a dynamic class for the body tag

in my base.html.twig my body looks like this:
<body>
{% block header %}{% endblock %}
{% block body %}
{% endblock %}
{% block footer %}{% endblock %}
{% block javascripts %}
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="{{ asset('/js/bootstrap.min.js') }}"></script>
<script src="{{ asset('/js/remodal.min.js') }}"></script>
<script src="{{ asset('/js/script.js') }}"></script>
{% endblock %}
</body>
Since my files homepage.html.twig and subpage.html.twig extend the file base.html.twig, I would like to pass a class to the body tag.
E.g. in my file homepage.html.twig I want it to be <body class="home"> and in my subpage.html.twig file I want it to be <body class="subpage">.
Is it possible to simply pass a variable or something like that or would it be necessary to use a block for that?
I found out that the easiest way is to simply define a block like this:
<body class="{% block body_class %}sub_page{% endblock %}">
Then only in homepage.html.twig using:
{% block body_class %}homepage{% endblock %}

Variable " asset_url" does not exist

Not sure what's wrong but I can't include javascript and/or stylesheet files. Using Symfony3
{% block javascripts %}
{% javascripts
'#AppBundle/assets/js/jquery.js'
'#AppBundle/assets/bootstrap/js/bootstrap.min.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
getting this error:
Variable " asset_url" does not exist in security/login.html.twig at line 32
Overall, the code should probably look like this:
{% block javascripts %}
{% javascripts
'#AppBundle/assets/js/jquery.js'
'#AppBundle/assets/bootstrap/js/bootstrap.min.js'
output='js/compiled/app.js' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
If it doesn't work then make sure that path to these files is correct.

Assets - How to hide bundle name?

When I launch this command :
assets:install web
Symfony copy my asset into something like :
web/bundles/mybundle/img/img.png
So when I use this ressources, I have to do something like that :
{{ asset("bundles/mybundle/img/img.png") }}
That way, this part "bundles/mybundle/" is public.
How can I hide this part ?
I know that it's easily done with assetics like that :
{% javascripts '#AcmeDemoBundle/Resources/public/js/*' output='js/main.js' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
But for media (images, videos...) it's a different story. Any Idea ?
Use Assetic for images as well as for js, then set the output to wherever you wish.
{% image '#AcmeFooBundle/Resources/public/images/example.jpg'
output='/images/example.jpg' %}
<img src="{{ asset_url }}" alt="Example"/>
{% endimage %}

Javascripts output variable for Assetic Bundle in Symfony2

Here is my code:
{% block js %}
{% javascripts filter='?yui_js' output='js/m/myfiles.js'
'#MyBundle/Resources/public/js/m/one.js'
'#MyBundle/Resources/public/js/m/two.js'
'#MyBundle/Resources/public/js/m/three.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
I would like to be able to change my output value based on variable.
something like this:
{% set myOutput = 'js/m/myfiles_v2.js'%}
{% block js %}
{% javascripts filter='?yui_js' output=myOutput
'#MyBundle/Resources/public/js/m/one.js'
'#MyBundle/Resources/public/js/m/two.js'
'#MyBundle/Resources/public/js/m/three.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
But when I do that i get "Unexpected token "name" of value "myOutput" ("string" expected). Is there a way around this?
I think you need to create own assetic filter which will extends yui_js filter and overwrite function to create name.
Assetic filter is a service implements FilterInterface.
Here is sample definition of you filter as service:
<service id="my.if.filter" class="MyBundle\FilterClass">
<tag name="assetic.filter" alias="my_alias" />
<argument></argument>
<argument>....</argument>
</service>
Here is a tutorial:
http://richardmiller.co.uk/2011/05/24/symfony2-make-your-own-assetic-filter/

Adding JS and CSS cleanly from included Twig templates

I'm looking to find out if there's a clean way to add JS and CSS from included templates.
So, for example, if layout.html.twig has:
{% include 'GenericBundle:Generic:page.html.twig' with {'data': data} %}
...
{% block javascript %}
{% javascripts
'#GenericBundle/Resources/public/js/app/jquery/jquery.min.js'
'#GenericBundle/Resources/public/js/lib/bootstrap/bootstrap.min.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
And in the generic bundle page I'd like to include some more Javascript but add it to the established Javascript block to keep to HTML and JS best practices.
Is there a clean way to do this? I'm using Symfony2, and could probably cludge together a solution using Singletons and such, but I'd rather a cleaner method if there's one available.
I know I'm a little late to the party, but with Twig 1.2, you can utilize the use tag and the block function:
GenericBundle:Generic:page.html.twig
{% block javascripts %}
<script src="..."></script>
{% endblock %}
{% block included_content %}
Bar
{% endblock %}
layout.html.twig
{% use 'GenericBundle:Generic:page.html.twig' with javascripts as page_javascripts %}
{% block javascript %}
{% javascripts
'#GenericBundle/Resources/public/js/app/jquery/jquery.min.js'
'#GenericBundle/Resources/public/js/lib/bootstrap/bootstrap.min.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{{ block('page_javascript') }} // Don't forget the 'braces'
{% endblock %}
...
{{ block('included_content') }} // Don't forget the 'braces'

Resources