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 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
    • By Robin S
      If you've ever needed to insert links to a large number of files within CKEditor you may have found that the standard PW link modal is a somewhat slow way to do it.
      This module provides a quicker way to insert links to files on the page being edited. You can insert a link to an individual file, or insert an unordered list of links to all files on the page with a single click.
      CKEditor Link Files
      Adds a menu to CKEditor to allow the quick insertion of links to files on the page being edited.

      Features
      Hover a menu item to see the "Description" of the corresponding file (if present). Click a menu item to insert a link to the corresponding file at the current cursor position. The filename is used as the link text. If you Alt-click a menu item the file description is used as the link text (with fallback to filename if no description entered). If text is currently selected in the editor then the selected text is used as the link text. Click "* Insert links to all files *" to insert an unordered list of links to all files on the page. Also works with the Alt-click option. Menu is built via AJAX so newly uploaded files are included in the menu without the page needing to be saved. However, descriptions are not available for newly uploaded files until the page is saved. There is an option in the module config to include files from Repeater fields in the edited page. Nested Repeater fields (files inside a Repeater inside another Repeater) are not supported. Installation
      Install the CKEditor Link Files module.
      For any CKEditor field where you want the "Insert link to file" dropdown menu to appear in the CKEditor toolbar, visit the field settings and add "LinkFilesMenu" to the "CKEditor Toolbar" settings field.
       
      http://modules.processwire.com/modules/cke-link-files/
      https://github.com/Toutouwai/CkeLinkFiles
    • By stanoliver
      Hi! 
      The following code snippet is part of my markup simple navigation and the url_redirect (url field in the backend) just works fine when I put an special custom url into the url_redirect field.
      <?php $nav = $modules->get("MarkupSimpleNavigation"); // topnav $current = $page->rootParent(); // current root page // subnav echo $nav->render(array( 'max_levels' => 2, 'item_tpl' => '<h4><a class="g8-bar-item g8-hover-black" href="{url_redirect|url}">{title}</a></h4><hr class="sidenav">', 'collapsed' => true, ), $page, $current); ?>  In my seperated breadcrumb navigation I use the following code snippet
      <?php foreach($page->parents()->append($page) as $parent) { echo "<li><a href='{$parent->url_redirect|url}'>{$parent->title}</a></li>"; } ?> Now to the problem: In my first code snippet above the
      url_redirect|url 
      works just fine but when I try something similiar in the second code snippet
      $parent->url_redirect|url
      I produce an server error How do I have to change the second code snippet so that it works in the correct way as the first code snippet does?
×
×
  • Create New...