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' %}
Related
I just build a blog for myself, build up by hexo and next.
Today i have known how to set one picture by this :
![image description](img's url)
But by this way i cant put two images on same line.It loos like this:
image1
image2
And this is what i want
image1 image2
I have checked disable fancybox and tried to use this (just write them at the same line):
![image description](img's url)![image description](img's url)
They are both no effect.
I didn't notice that it's the solution of NEXT theme,so I cannot guarantee the answer is still valid.
Original answer:
I also tried to do that before,but failed many times.
Eventually I got the answer in Official Reference Document.
To be brief,use the format below to insert your imgs.
{% gp [number]-[layout] %}
![image description](img's url)
![image description](img's url)
{% endgp %}
[number] is the amount of your imgs.
[layout] is the index of the designed layout. (you can see specific
layouts in the Document)
P.S. The Document recommends enabling the "fancybox" plugin,which I did.
So I am not sure whether it would operate normally without enabling fancybox.Please notice!
For example,you can get:
"image1 image2" (you mentioned in your question)
by using the code below:
{% gp 2-2 %}
![image description](img's url)
![image description](img's url)
{% endgp %}
Hope my answer would be helpful! I kown it's really a struggle to grope alone. :)))
I dont understand what does # do in this routing?
exemple:
{% extends "#User/Default/index.html.twig" %}
i am trying to find the file that is extended but unable to do so.
Thanks to the comment left by #Cerad I found it using: bin/console debug:twig
#User src\UserBundle/Resources/views\
Usually, when you refer to a template, you'll use the MyBundle:User:index.html.twig format.
Twig also natively offers a feature called "namespaced paths", and support is built-in automatically for all of your bundles.
Take the following paths as an example:
{% extends "MyBundle:User:layout.html.twig" %}
With namespaced paths, the following works as well:
{% extends "#App/layout.html.twig" %}
Both paths are valid and functional by default in Symfony.
I am working on a proof-of-concept project that needs to be built quickly, so we are taking shortcuts. I have created the basic Symfony/Twig structure. A colleague has created a PHP application that we want to include into an iFrame on the site (eventually we will do this by means of proper templates, etc.).
I created the following index.html.twig (simplified):
{% extends 'base.html.twig' %}
{% block body %}
<iframe src="project/index.php"></iframe>
{% endblock %}
This throws me an error:
Unable to find template "project/index.php"
I understand the error, but am not sure what to do so that the external application simply gets loaded into the iFrame. Basically I want Symfony and Twig to ignore it (for now, so it can be used as prove of concept).
I will make an assumption here, specifically, that your code is included in a template for /app/somethingelse (two slashes or more).
which will lead to, the uri in the following (your code)
<iframe src="project/index.php"></iframe>
to be interpreted as /app/project/index.php - since it's a relative path -, which most likely doesn't exist. What you probably want is an absolute path (which always begins with a slash):
{% block body %}
<iframe src="/project/index.php"></iframe>
{% endblock %}{# ^here #}
I suggest reading up on relative vs. absolute paths. combined with the comment, that you almost always want absolute paths (unless full URLs are necessary of course) - this also includes paths to images, paths to css files, paths to anything and everything really. relative paths can be quite handy, but you always have to be aware that the relative position of locations gets relevant and cannot be changed without impacting other places where those relative positions are assumed to be static.
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!
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