Is it possible to get the content representation of a page within the template? Like $page->representation()?
I’m using content representations to display content in different ways depending on whether the user is viewing (/my-page) or editing (my-page.admin) the page. I use very distinct code for the main part of the page, but for things like menu things don’t change across representations so I rely on snippets. Within those snippets, very small things do change, like adding “(editing)” next to the title. I don’t want to have to duplicate the entire snippet for each representation. It would be nice to be able to do:
This is not necessary, you can pass variables to your snippet. So when calling the snippet in the “admin” representation, you can call your snippet like this:
Thanks @texnixe! That’s actually how I’ve been doing it until now, but this new site is larger: ~10 templates * 3 representations = ~30 places where I have to manually pass, at least, a $representation var. It’s not the end of the world, of course, but I was hoping there would be a way to get that value more elegantly.
It’s a bit of a different question, but to generate URLs I’m facing a similar challenge in that I have to build them manually like:
Keep in mind representation() is already taken and it’s a returning the representation itself, not checking for the type. Same goes for the url() method. It expects a language string, not an appendix for the url. But of course it’s possible to write a custom page method for this use case, too.