Append onto current URL with Twig? - php

I'm currently making a simple file hosting script using Slim, Twig, and PHP. Right now I'm trying to append onto the current URL using Twig but am not sure how to do this. I've tried /panel/{{ newURL }} but it always just redirects me to /panel/newurl. I need to be able to dynamically update this URL.
For example, if I want to go to /tests on /panel/core/ I need to be able to append that onto the current URL. Does Twig offer a way to do this? Thanks.

Do you use Twig to render your paths? I think your application should always be able to resolve the paths, so also let the application itself render them ;-)
If that would help; you can add the parameters of the current request to the path rendering:
{{ path('yourpath', app.request.query.all|merge({'myparam': 'value'})) }}

you can use the Built-in parameter in twig {{ app.request.uri.path }}

You'll want to ensure that you've included all route and query string parameters in the URL you're appending to.
Here's an example of appending foo=bar to the current URL:
{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge(app.request.query.all)|merge({'foo': 'bar})) }}

I ended up just passing 'url' => $request->getUri()->getPath() in my view parameters. I think this is a pretty decent method because there are other methods you can call on getUri() to get different results depending on what you want to do.

Related

Access to a block view in a paragraph in Drupal

I created a paragraph in drupal which has a reference to a block.
In the preprocess I did :
$variables['bloc_video'] = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($bp);
And in my twig file I just called it like that :
{{bloc_video}}
The view is unfortunately not correct.
I want my preprocess to call my block view in another twig file. How can I do that?
Thanks a lot
I suggest using Twig Tweak module (it is very useful also for other cases). Here you can find more about including blocks in twig with Twig Tweak module.
In you case you can use:
{{ drupal_entity('block', 'block_content') }}
However, if you would still like to do it programmatically, check this answer.

How to use javascript(Angular.js) with laravel get php url(asset)

I use javascript(Angular.js) with laravel
<aside data-ng-include=" {{ asset('layout/nav') }} " id="nav-container"></aside>
but is error:NotFoundHttpException load no path,
What can be read into the .php file?
Im a little confused on what you are trying to do, but it seems that you are using asset() to link a directory. I would use the laravel function link_to() instead, since it is made to generate links to paths.
Here is the link to the laravel documentation with more information on link_to() and asset():
http://laravel.com/docs/4.2/helpers#urls

Removing StripSlash in Blade Ouput

I would like to remove the stripslash "\" character from my database search result.
Instead of using {{stripslashes($output->var)}}, which add a PHP function on every output in blade, can I do it GLOBALLY in the BladeCompiler file?
I want to apply this change in every output {{ }} in my Laravel site, any suggestion? I tried to modify the Bladecompiler file compileRegularEchos function, seems not working, please advice
I'm assuming you're using Laravel 5 because Blade templating defaults to escaping now. If you want to echo something without escaping you can use this syntax:
{!! $output->var !!}
For more info you can check the Blade docs

generating url not based off subdomain's in twig

I have followed the following tutorial to handle dynamic subdomains. So say the redirection is successful and I am already at www.subdomain.domain.com. Now when I click on other links in the site it goes to www.subdomain.domain.com/myotherlink, while in fact all of my links should go to www.domain.com/myotherlink. Here's how I generate links in my twig file:
{{ path('MyAppMainBundle_marketplace') }}
The route in the controller looks something like this:
/**
* #Route("", name="MyAppMainBundle_marketplace", options={"sitemap" = true})
* #Template("MyAppMainBundle:MarketPlace:index.html.twig")
*/
How do I enforce such that all links on my site that is generated using the twig syntax above goes to mydomain.com/myotherlink? I think the issue is I don't want a relative path. I wanted an absolute path? I tried replacing path above with url, however it didn't work
A little more information on exactly what the template you are using is creating the link in question, but I think this other stackoverflow answer might help:
https://stackoverflow.com/a/9750494/1978759
Hope this helps.

PHP redirect - break out of iframe

I know this is very basic and I've never had the need before, but I want a PHP redirect to break out of any iframe (if applicable).
Is this possible?
I know that PHP sends a header to the browser, so it should be, but I can't see this anywhere.
So if I use this code then it always changes the parent and not just any iframe window:
<?php
header('Location: http://domain.com/');
?>
Of course this works, but I need it done from PHP:
<a href="page.php" target="_parent">
I'm using Symfony2 so will need to get it working in that too.
No JavaScript. PHP only (if possible).
You can't do it in PHP - if the browser is trying to load the page in a frame, then sending a Location header will simply load the new page in the frame too.
If you're trying to stop others from putting your site in a frame, you'd have to use JavaScript to detect it and do the redirect, otherwise target="_top" is the right approach.
From your controller in Symfony 2, return some variable (for example reloadMyIframe) then, when you want to reload your iframe. Then in view (twig probably), put something like this
{% if reloadMyIframe == true %}
// Add somethin like this <script...>window.parent.location.href = "http://jourTaret.dmn"
{% endif %}
If your view in Symfony is in PHP, you can use same logic just type it with php if statement.
As the guys have already said, there is no way to accomplish what you are trying to just with PHP or from Symfony controller.

Categories