Reference error Sfjs is not defined - symfony

I just started with symfony, on template I simply define:
{% javascripts "#MyBundle/Resources/public/js/app.js" %}
<script src="{{asset_url}}"></script>
{% endjavascripts %}
right before closing body tag </body>.
I get this javascript error:
ReferenceError: Sfjs is not defined
It seems like my javascript is affecting symfony debugbar script. but its happen even when my app.js contains nothing. How should I fix this ? thanks.

Although this is an old topic with an already found untold solution, I just wanted to share my experience that when I was confronted with the same error, it was due to the fact that I had forgotten to add a closing </script> tag somewhere in my base template.

I'm relatively new to Symfony myself, but I believe you need to put spaces between the brackets and the variable. In other words, the second line should look like this:
<script src="{{ asset_url }}"></script>
That should help Symfony find the script, which will allow the toolbar to show up.
Hope that helps!

Related

AMP: External amp css using {%...%}

I keep seeing people say AMP pages must have the css code all inline in the custom tag, but on the website it seems to say you can reference it from an external file for when its from a preprocessor: https://www.ampproject.org/docs/guides/responsive/style_pages#using-css-preprocessors
Can someone tell me if I'm interpreting this wrong? Thank you!
{% include "/assets/css/main.min.css" %} is Twig Tag (The flexible, fast, and secure template engine for PHP). For more details Click Here
You can use like this if using PHP language
<style amp-custom>
<?php include("styles.css"); ?>
</style>
include : The include statement includes and evaluates the specified file.
Note : styles.css is external css

What's the difference between the include tag and the include function?

I saw someone including a template on his application using the twig template system.
He included his template like this:
{{ include( 'Bundlename:Directory:template.html.twig' ) }}
instead of this:
{% include 'Bundlename:Directory:template.html.twig' %}
At first I thought he was using a custom twig extension, but it actually
works on symfony in general, even though its not documented.
http://twig.sensiolabs.org/doc/tags/include.html
So is there a difference between the two?
why is it not documented?
if the syntax is wrong why is it even working?
It is documented http://twig.sensiolabs.org/doc/functions/include.html.
Twig tag include vs function include

Symfony special characters in Twig file causing error

For pages with lots of text and html tags, I quickly get a parsing error from Twig due to unexpected special characters. Has anybody else ran into this problem?
Unexpected character "!" in ... at line 76
I am trying to fix this problem by pasting the static information in a new page and then including it using include.
My question is, where should I place a static HTML file so it can be included in a Twig file using {% include 'content.html' %}? Currently the included file is in the FooBundle/Resources/views/Default directory.
What is a good practice for overcoming this problem, and if include is the answer, where should the file be located to be included in a twig?
Note:
When I try to link to it using {% include 'content.html' %} I get the following Symfony error:
Unable to find template "content.html" in ... at line 31 (broken link)
I found a solution, drawing from various different posts. I ended up putting the raw html in a new file (which isn't required) and included it as follows:
{% include 'FooBundle:Default:content.html.twig' %}
Then inside my content.html.twig I surrounded my raw HTML code with raw Twig tags:
{% raw %}
// RAW HTML CODE HERE
{% endraw %}
Include like this
{% include 'YourProjectNameFooBundle:Default/content.html.twig' %}

Message: You have requested a non-existent service "http"

I have a problem with render tag in twig.
I got a message: "You have requested a non-existent service "http". When i use {% render url("render_menu") %}
render_menu route works fine
help me !
P/S: Sorry about my english
You use a correct way, but with an old version. You should upgrade to fix security issues AND resolve your problem.
A security issue changed the way to use render: http://symfony.com/blog/security-release-symfony-2-0-20-and-2-1-5-released
Documentation has been updated:
http://symfony.com/doc/2.0/book/http_cache.html#using-edge-side-includes
You are using render tag wrong. If you want to render action, that is behind your render_menu - you should pass it in format YourBundle:YourController:YourAction.
For example, if you have menuAction() that is behind route render_menu, then in Twig you should call it like this:
{% render "YourBundle:YourController:menu" %}
Note, that you have to strip out Action word when calling menuAction in render tag.

how to use the css and images in a bundle?

I'm new in symfony2, and I'm confused how to use css and image by asset.
For example, I have a boundle named userbundle, and i put my css and image in UserBundle/Resources/public/css and UserBundle/Resources/public/image. But by asset, they were located in web/acmeuser/css and web/acmeuser/image. They do not exist and of-course I can not show them.
answer:
The problem is because of the svn. If you have svn in both sides, which means in src/bundles and in web/bundles. If both of them is in svn control, then the command
assets:install web
will cause this exception:
unlink(web//bundles/framework\images.svn\text-base\open_quote.gif.svn-base): Permission denied in \vendor\symfony\src\Symfony\Component\HttpKernel\Util\Filesystem.php on line 101
If you just removed your /web/bundles and set svn ignore to it. rerun the command and all goes well.
You can try this.
{% block javascript %}
<link rel="stylesheet" type="text/css" href="{{ asset('bundles/UserBoundle/Resources/public/css/Filename.css') }}" ></link>
<script type="text/javascript" src="{{ asset('bundles/UserBoundle/Resources/public/js/Filename.js') }}">
</script>
{% endblock %}

Resources