Robin S Posted March 16, 2016 Share Posted March 16, 2016 I have some pages that are used only as partials, to be rendered as part of other pages using $page->render() I have them inside a /widgets/ branch in my page tree. The problem is that they are viewable from the front-end: if someone visits mydomain.com/widgets/my-widget/ they see the partial HTML. Is there a way I can keep my widgets accessible to editors in the back-end and capable of being rendered in other pages but without them being directly viewable? 1 Link to comment Share on other sites More sharing options...
mr-fan Posted March 16, 2016 Share Posted March 16, 2016 Pseudocode from my Phone... If page->template = widget Perfom a 404 error Have a search with Google on the forum About 404 errors and hiding Pages in Frontend... Regards mr-fan 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 16, 2016 Share Posted March 16, 2016 To not copy my suggestion again: https://processwire.com/talk/topic/12409-prohibit-view-of-pages-with-certain-template/ I'd really refrain from using $page->render() for rendering partials in favor of wireRenderFile(). 4 Link to comment Share on other sites More sharing options...
Robin S Posted March 17, 2016 Author Share Posted March 17, 2016 Thanks for the ideas. @mr-fan: I think this might be the sort of thing you're hinting at - at the top of the widget templates... <?php if( empty($options['pageStack']) ) throw new Wire404Exception(); ?> Good info in this post from Jonathan Lahijani here and some info on pageStack from Ryan here. I like this solution. @LostKobrakai: Sounds like this would work, but it seems to me there are downsides to using wireRenderFile() over $page->render(). I have a lot of different widget templates and widgets are selected by editors via a page field, so using $page->render() keeps the rendering code really simple and maintenance-free. foreach($page->widgets as $widget) { echo $widget->render(); } But if I use wireRenderFile() I need a whole chain of logic to check the template of each widget and render it with the correct file for that type of widget. Besides avoiding partial pages being directly viewable, are there other benefits of wireRenderFile() that make it preferable to $page->render()? 4 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now