// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knplabs/knp-time-bundle": "^1.8", // 1.8.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.0.0
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"sensio/framework-extra-bundle": "^5.1", // v5.1.4
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.0.4
"symfony/console": "^4.0", // v4.0.14
"symfony/flex": "^1.0", // v1.21.6
"symfony/framework-bundle": "^4.0", // v4.0.14
"symfony/lts": "^4@dev", // dev-master
"symfony/twig-bundle": "^4.0", // v4.0.4
"symfony/web-server-bundle": "^4.0", // v4.0.4
"symfony/yaml": "^4.0" // v4.0.14
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.4
"fzaninotto/faker": "^1.7", // v1.7.1
"symfony/debug-bundle": "^3.3|^4.0", // v4.0.4
"symfony/dotenv": "^4.0", // v4.0.14
"symfony/maker-bundle": "^1.0", // v1.4.0
"symfony/monolog-bundle": "^3.0", // v3.1.2
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.0.4
"symfony/stopwatch": "^3.3|^4.0", // v4.0.4
"symfony/var-dumper": "^3.3|^4.0", // v4.0.4
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.0.4
}
}
19 Comments
Hi Ryan,
Could you point me out where exactly you did the markdown cache ? (There many cache turotial i would find the one for the markdwon)
Hey Dylan Delobel ☕!
Sure :). We did that work in this tutorial: https://knpuniversity.com/s..., but most specifically, this chapter: https://knpuniversity.com/s.... Basically, we use Symfony's built-in cache system to create a new MarkdownHelper service that is processes the markdown, but caches the results. Then, we're using that in this tutorial.
Let me know if that helps! Cheers!
Sort of an off-topic. It seems that the error message re:H264 decoding seems outdated (Firefox/Linux). Either ffmpeg or libav packages would work instead of gstreamer. Packman has all packages if on SUSE.
Hey @Chris
Where did you get this error message? Does it produce some issues with course for you?
Cheers!
<b>Goal:</b>
Due to SEO reasons, I need a couple of <meta> tags on every page.
Lets say, we have 3 blocks:
That would be working, every block could be overwritten.
But its not very "error resistant", I mean a dev could miss any of this blocks on a children twig templates.
<b>Question:</b>
Is there a way to "enforce" that every 3 blocks should be set (to avoid errors if the dev "forget" one block?
What is the best solution?
I thought about a custom twig function, like in this tutorial, with 3 parameters and one is optional (canonical)
Is a twig function for this use case the way to go?
Hey Mike,
Interesting question! As far as I know it's impossible to do with Twig block out of the box. Probably, the best solution I can see is to use a variable in the parent template that will be declared in the child template. If you didn't set that variable - you will see the error on the page.
I think you can do something similar with custom Twig function, but you would also need a listener probably. Like you inject a special service in that Twig extension for your custom Twig function and if the specific argument was passed - remember it with that service, like a boolean flag. Then in the listener, you listen for the latest event, .e.g. terminate event and check if that bool flag was set on that service. If no - throw an exception with a clear error message.
But fairly speaking, this work sounds like a job for tests, so you can just write test that will ping every unique route you have and check if the response contains specific content. Though, this test may take some time to execute, depends on how many unique routes you have.
I hope this helps!
Cheers!
I'am always impressed of your detailed answers!
You helped me a lot, thank you Victor!
My solution:
Hey Mike!
Thank you! I do my best :) I'm happy it helped you, and thanks for sharing your solution with others!
Cheers!
I missed the part where we removed the debug check and didnt cache in debug mode.
I had a problem with auto escaping even when added "
['is_safe' => ['html']]
" argument.
I checked twig documentation to find out why escaping is still on and there is solution, following documentation:
"Some filters may need to work on input that is already escaped or safe, for
example when adding (safe) HTML tags to originally unsafe output. In such a
case, set the pre_escape option to escape the input data before it is run
through your filter:"
So if someone will have the same problem just add this argument :
['pre_escape' => 'html', 'is_safe' => ['html']]
instead of only
['is_safe' => ['html']]
Nice find! Thanks for the note Dominik!
Hi Guys,
i get the following error when adding the constructor function :
Cannot autowire service "App\Twig\AppExtension": argument "$markdownHelper" of method "__construct()" has type "App\Service\MarkdownHelper" but this class was not found.
Wtf ?!
The code is exactly the same like the tutorial code.
Hey Kristof Kreimeyer!
Ah no, lame! Let's see if we can figure this out :). Fortunately, these errors are designed to be pretty good. The key part is the end of it:
This tells me that your type-hint is correct (this IS the correct class that we should be type-hinting) but, for some reason, that's not found. That IS definitely mysterious... especially because we created that in a previous tutorial (so if you downloaded the start code, that file should be perfect). To experiment, can you reference that class directly in, for example, a controller? Specifically, the ArticleController::show() method should already be using it (before this chapter):
Does this endpoint work for you? Or do you get a similar error?
Cheers!
How I can use existing twig function in an extension?
---> EDIT <---
My solution:
Hey Krzysztof K.!
Great question! And a very interesting solution! Honestly, I didn't know you could do this :).
Let me describe another solution. Actually, this solution would *not* work in this case, but it's *usually* what I do.
1) You find where the function/filter you want is implemented. For example: https://github.com/symfony/...
2) Then, you reverse engineer what it is doing and do that yourself. In almost all cases, a Twig function/filter is just calling a method on some service. So, you can just fetch that same service and call the same method. This does NOT work in this case because, oddly, all the logic is actually *inside* that Twig Extension. So, your solution is probably the best.
Cheers!
$this->markdownHelper->parse($value) and not $this->helper->parse($value) as said before the last code block. :)
Hey Chris,
Good catch! Thanks for reporting it. But actually that line is in sync with the video, we use "$this->helper" in this screencast, but in the code it's "$this->markdownHelper" - a little discrepancy we had in this screencast :)
Cheers!
in my opinion, use Twig\TwigFunction; should be removed from AppExtension Service :)
Hey Ad F. ,
Yes, you're right. Maker bundle had autogenerated us a few examples with TwigFilter and TwigFunction, but then we removed that TwigFunction at all, so the use statement no needed anymore. But nothing harmful if you keep it, well, at except PhpStorm warning about unused namespace ;)
Cheers!
"Houston: no signs of life"
Start the conversation!