Jump to content
Sign in to follow this  
photoman355

Redirect admin view links for one page website?

Recommended Posts

I'm building a template for a one page website and have run into a small problem with the admin view page links.  

Because my site is built with content blocks rather than pages there is no header and footer for each block, only the homepage needs to pull in the header and footer for the site.  As a result clicking to view a page in the admin shows the page content but with zero styling.  This is obviously not ideal for clients so I'd like to find a better solution.

Here's a rough idea of the site structure:

    Home  (header & footer)

        Page 1

            Content Block 1

            Content Block 2

        Page 2

            Content Block 3 etc etc

My page's use an anchor # for the url eg #contact so Ideally when the user clicks on the page they'd be redirected to that relevant anchor.  I know this might be complicated to achieve so all I really need to do is redirect all pages to the homepage (parent).  

Any idea how I would go about this? 

Share this post


Link to post
Share on other sites

If you use a different template on the pages that shouldn't be view-able (I assume everything but home), and that template does not have an associated file (example "basic-page" template has "basic-page.php") then the view button itself will not be shown. 

Another option is maybe to just use a repeater for the content blocks and then genuinely only have one page in the admin (home) and remove the other.

Hope that helps.

  • Like 1

Share this post


Link to post
Share on other sites

just tell them not to view page in the admin, or make those pages redirect to the anchor on the homepage, using some php in the template file (?)

Share this post


Link to post
Share on other sites

Thanks guys.  @adamspruijt I'm not quite sure what you mean by 

If you use a different template on the pages that shouldn't be view-able (I assume everything but home), and that template does not have an associated file (example "basic-page" template has "basic-page.php") then the view button itself will not be shown. 

Do you mean creating templates via admin without creating a physical template file?  All my blocks contain markup so they're built as separate eg block.php files.

I'm not familiar with the repeater field technique for content blocks.  Can you explain a bit more?

One workaround I thought of would be to add this to my admin template css which solves the problem up to a point.  

.content .PageListActionView {
  display: none !important;
}

 I was hoping there would be a nice simple way to handle it in Processwire. I know there's the redirect module but that's not ideal is it involves specifying each url and all I really need is a global rule that says - if child redirect to parent, or something like that.  

@Macrura can you give me an example of how I would add a redirect to a template?

Share this post


Link to post
Share on other sites
<?php 
$homepage = $pages->get('/'); 
if($page != $homepage) { // if we're not on the homepage do this
	$redurl = $homepage->url . "#" . $page->name; // this is where the page will redirect to
	$session->redirect($redurl);
}
?>

don't do it this way - it won't work right on the homepage - look at diogo's post below.

Edited by Macrura

Share this post


Link to post
Share on other sites

Thanks guys.  @adamspruijt I'm not quite sure what you mean by 

Do you mean creating templates via admin without creating a physical template file?  All my blocks contain markup so they're built as separate eg block.php files.

I'm not familiar with the repeater field technique for content blocks.  Can you explain a bit more?

Yes, I am talking about having a template without a file, you could probably move those templates that are not supposed to be view-able  like "block.php" into an "includes" folder and then use simple code to grab the right file based on the template name like this (assuming you've gotten the pages you need in the variable "$blocks"):

<?php 
foreach ($blocks as $block) {
	include("./includes/".$block->template.".php");
}
?>

 For the repeater method this would work only assuming the content in the "blocks" was very simple and could be handle with basic "Textarea/TinyMCE" fields, I didn't realize you mentioned #contact. Assuming the contact area requires a form or more advanced fields, what I mentioned first above would work best.

Share this post


Link to post
Share on other sites

Macrura, your solution won't work because inside the render() the $page object is the one from the rendered template, so ($page != $homepage) will always be true.

But the same can be achieved by testing agains the url:

if($page->url == $_SERVER[REQUEST_URI]) $session->redirect($pages->get(1)->url."#".$page->name);

and in the homepage, something like:

foreach($page->children as $p) {
    echo "<div id='{$p->name}'>";
    echo $p->render();
    echo "</div>";
}

  • Like 1

Share this post


Link to post
Share on other sites

@diogo - i thought that in this case the link from the admin was actually rendering the page at it's correct URL, like:

/page1/content-block-1

which is why i thought that would work... unless i'm missing something...

Share this post


Link to post
Share on other sites

What happens with render is that the $page object is momentarily replaced by the rendered page, so if you render a page inside the homepage, and in that page template you compare $page != $homepage, this will always be true. By doing like I did, you are comparing the real url in the browser with the rendered page url. This means that if the page it's called directly, the real url and the url from the $page object will match, but if the page is rendered from another page they won't.

  • Like 1

Share this post


Link to post
Share on other sites

Ok so I think what you are saying that when the homepage renders the content blocks, which are being done with the render method, the check I wrote won't work because the $page object is still not really 'home'; so i get that now, and will edit the code in my post..

Share this post


Link to post
Share on other sites

Thanks guys.  @adamspruijt, I never thought of adding blocks like that.  Definitely fast to deploy a site but one advantage of building with blocks as children is the blocks can be changed without touching the source.  I'm sure this could be set up via an of options page though.

@diogo Looks like a fairly straightforward solution, look forward to testing it out.  Much appreciated.

Share this post


Link to post
Share on other sites

Thanks guys.  @adamspruijt, I never thought of adding blocks like that.  Definitely fast to deploy a site but one advantage of building with blocks as children is the blocks can be changed without touching the source.  I'm sure this could be set up via an of options page though.

Why would you need to change the source? The structure of the block would be defined in the includes and ordered based on their order in the admin, unless your adding a new "block type", otherwise you should be able to add new content indefinitely. I don't think I know enough about what you're doing, you may not require the flexibility I'm picturing.

Regardless the redirect works, and allows you to have the view buttons intact on the back end, which could be nice.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By EyeDentify
      Hello dear PW gurus.

      I have stumbled over a strange error that i all of sudden got when trying to upload an image to a images field on a page.
      There where images allready stored in the field that i wanted to keep, but during the upload the error apear and after that all images are gone from the field and i can´t upload any, i just get the error every time.
      I am running ProcessWire 3.0.153 dev.
      Update:
      After looking in the assets folder i find the folder for the page and the image files seems to be there including the ones i tried to upload when the error occured.
      But they don´t show up in the images field in the page editor.
       
      The error reported:
       
      SQLSTATE[01000]: Warning: 1265 Data truncated for column 'ratio' at row 1 And here is a screenshot of the event:

      The TracyDebugger Error reporting:

      I hope you fine folks could point me in a direction.
      But it seems our old pal set_time_limit() is back.

      Regards, EyeDentify
    • By Spyros
      Hello
      I'm having a strange issue with the $page->find(), for some reason I'm missing some of the pages from the results. I found then that I was missing all the pages with the same "PAGE NAME". Is it a bug or am I missing something?
      PS 
      If I change the "PAGE NAME" of one of the missing ones then I'm retrieving the page without any problem.
      Thank you
    • By benbyf
      Hi, Looking to create form elements on a page–some input with a colection of form inputs and the appropriate labels and variables for that input. I've used ProForms in the past and rolled out my own when creating simply one off forms, but I wonder if anyone has found a good way of allowing form creation on page editing so that clients can adhocly make and edit forms?
      Thanks
    • By EyeDentify
      Hello Dear PW Gurus.

      Hope you fair well in these Corona Crisis times.

      Anyhow, i have a problem with a Cryptic error message that shows up when i am trying to Delete images out of a Images field.
      The Error message does say a little but it does not make sense to me why i can´t delete the images because of it.

      Is it some permission issue perhaps?

      I will attach screenshots of it and what i did prior to it.
      I am from sweden so ignore the funny words here and there.

      Hope you all can send me on the right track.
      i am running PW 3.0.139 on this install.

      Step1:

      Step 2: Select the images with the trashcan symbol

       
      Step 3: Cryptic Error message

      I am scratching my head on this one, have not seen this before.

      Thankfull for all help.
      /EyeDentify
×
×
  • Create New...