Use different template when loaded in iframe

I want to load a subpage in an iframe in the parent page. When the subpage is loaded in the iframe it should use another template then when it is loaded in a blank browser window. Is that possible?
Or is there a condition that checks the parent fo being an iframe?

Preferably the url also changes to the url of the subpage, and when you paste that url in the address bar, it would go to the parents page with the child loaded in the iframe.

Thank you!!

Why use iframes in the first place? :eyes:

There are almost always better architectural solutions then resorting to iframes.

Tell me more :slight_smile: I obviously am not aware of those

The question is what is the purpose of using an iframe here? Please describe your use case.

That doesn’t make sense, you cannot show two different things using the same URL.

Here is an example: https://stimuleringsfonds.nl/
click on any article under news: the article loads on top of the site, and the url changes.

But if there is another way to inject the content of a page into another one that would help me a great bit. The template problem would then be easy to solve myself.
Thanks!

But that is not an iframe but the new page is loaded into the site via JavaScript.

Using a different template is possible via Content Representations, in this case you would return a JSON representation to your calling AJAX call.

I agree with @texnixe here. And if you want to apply best practices, make the website work in a normal way first: make sure links open to their “own page” first. When you got that in place you can “enhance” this by hijacking the link’s regular behavior with Javascript and load in the article on the current page (AJAX) + swap url history (JS).

That way your website will also work for users without javascript, and you won’t have to come up with a frontend routing mechanism for users coming in via the direct url, etc…

I’d suggest http://barba.js.org if you’re after strange/unique page loads.