Results 1 to 10 of 10

Thread: URL with .html#begin

  1. #1
    New user
    Join Date
    05-08-11.
    Posts
    7

    Default URL with .html#begin

    I want to add #begin after .html in the url (thus html#begin) , in order to open a webpage at a certain point of the page on small screens.

    I can add

    <a name="begin"></a></p> wthin the main content block (thus after <div id="main"> ) of a page

    When I enter

    #begin</p> in a text content block at the bottom of this page, a jump can be made from the bottom to where

    <a name="begin"> is located in the page.


    But how can I add it to the url, so that this functionality also works from the menu. If I edit in the page the input block "page alias", it doesn't acccept the #.
    I also already tried the internal and external redirect page type, but I could not find anything that works.

    For me it would also be fine if I could set the URL suffix in System - Setting to .html#begin, thus for all pages.

    It would be nice if somebody knows a solution to this problem. Thanks

  2. #2
    Community-Moderator xchs's Avatar
    Join Date
    06-19-09.
    Posts
    1,287

    Default Re: URL with .html#begin

    Hi Bert,

    you can do this with a page of type "External redirect". For the "Link target" choose a page hidden from navigation.
    Contao Community Moderator
    → Support options

  3. #3
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: URL with .html#begin

    You can also tap into Contao's "generateFrontendUrl" hook to add this --

    /system/modules/make-up-a-folder-name/config/config.php:
    Code:
    <?php $GLOBALS['TL_HOOKS']['generateFrontendUrl'][] = array('CustomUrls', 'generateCustomUrl'); ?>
    /system/modules/same-folder-as-above/CustomUrls.php:
    Code:
    <?php
    	class CustomUrls
    	{
    		public function generateCustomUrl($arrRow, $strParams, $strUrl)
    		{
    			return $strUrl . '#begin';
    		}
    	}
    ?>
    And then "#begin" will automatically be appended to any URL generated by the system.
    Brian

  4. #4
    New user
    Join Date
    05-08-11.
    Posts
    7

    Default Re: URL with .html#begin

    Dear xchs,

    I tried your suggestion.

    I put in page A an external redirect towards the hidden page B. The menu now shows the alias of the hidden page B instead of the alias of page A. I think sofar, sogood.

    But when I click on the menu entree, the system jumps to the rootpage of the website, instead of page B to which is being redirected.

    Then I changed it to an internal redirect. The menu shows the alias of page A now. When I click the menu entree, it jumps to page B, indeed. But, the anchor in page B does not work!
    (There is also nothing that activates this anchor, I think)

    So, later today, I will try the other suggestion I received from Medianomaly.

    Regards,
    Bert

  5. #5
    Community-Moderator xchs's Avatar
    Join Date
    06-19-09.
    Posts
    1,287

    Default Re: URL with .html#begin

    Quote Originally Posted by Bert
    The menu now shows the alias of the hidden page B instead of the alias of page A.
    How the menu can show the alias of that hidden page B when you have configured in the page settings to hide this page from navigation?

    I tried it in the Contao Online Demo and it works like a charm.
    Contao Community Moderator
    → Support options

  6. #6
    Community-Moderator xchs's Avatar
    Join Date
    06-19-09.
    Posts
    1,287

    Default Re: URL with .html#begin

    Try the following steps in the Contao Online Demo:

    • Open the back end module "Articles"[/*:m:38z7kkg3]
    • Edit the article "The academy"[/*:m:38z7kkg3]
    • Add after the last element a new content element of type "HTML" (or "Text" or whatever)[/*:m:38z7kkg3]
    • Add into the (HTML) textarea your anchor link, e.g.
      Code:
      <a name="begin"></a></p>
      Save and close.[/*:m:38z7kkg3]
    • Open the back end module "Site structure"[/*:m:38z7kkg3]
    • Edit the page "The academy" and clear the field "Page alias". Save and close.[/*:m:38z7kkg3]
    • Duplicate ("green plus icon") the page "The academy" and paste it for example after the page "The academy"[/*:m:38z7kkg3]
    • In the field "Page name" enter for example "The academy (B)" and into the field "Page alias" the word "academy" (i.e. the alias of your page A)[/*:m:38z7kkg3]
    • Choose the options "Hide from navigation" and "Publish page". Save and close.[/*:m:38z7kkg3]
    • Open the back end module "Articles"[/*:m:38z7kkg3]
    • Delete the article "The academy" from page "The academy" (your page A)[/*:m:38z7kkg3]
    • For the other article "The academy" on the new page "The academy (B)" toggle the visibility icon ("eye") to publish this new article[/*:m:38z7kkg3]
    • Return to the back end module "Site structure"[/*:m:38z7kkg3]
    • Edit the page "The academy" change the "Page type" from "Regular page" to "External redirect" and enter into the field "Link target" the alias of page "The academy (B)" (which actually should be "academy"). Add the URL suffix and your anchor link, too: "academy.html#begin". Save and close.[/*:m:38z7kkg3]
    • Done. [/*:m:38z7kkg3]
    Contao Community Moderator
    → Support options

  7. #7
    New user
    Join Date
    05-08-11.
    Posts
    7

    Default Re: URL with .html#begin

    Dear xchs,

    In page B the page alias was different from the page title; it should not matter. But now I made page name, alias, and title, the same.
    I went back to external redirect. The menu still shows page B (which is not a problem at all), and, indeed, it now jumps to page B.
    Now I added #begin to the linktarget in Page A again. And now it works !!!! Like a charm !!!
    (menu shows page B#begin, this is not a problem for me)

    Thank you very much for you support.
    Bert

    P.S: The only disadvantage is that I have to make a lot of extra pages. So I will also try the ohter suggestion. But at least, I have someting that works.

  8. #8
    New user
    Join Date
    05-08-11.
    Posts
    7

    Default Re: URL with .html#begin

    Dear Medianomaly,

    I added the files from your reply, and saved them as UTF-8 code. This does not add #begin, and the web page is totally blank.

    I saved them as ASNSI: the same result: a blank webpage.
    I saved theme as uni-code: it works again, but it does not jump to #begin, and it does not add #begin to the URL

    It shows now at the top the the webapges: ??<?php $GLOBALS['TL_HOOKS']['generateFrontendUrl'][] = array('CustomUrls', 'generateCustomUrl'); ?>

    Perhaps an additional thought ?

    Bert

  9. #9
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: URL with .html#begin

    I just tested it. It works as I see '#begin' at the end of all the links.

    I'm not sure what you mean -- I cut and pasted my own code into new files in my source editor. No issues.

    You can also type it in yourself if you have to -- just a few lines of code.
    Brian

  10. #10
    New user
    Join Date
    05-08-11.
    Posts
    7

    Default Re: URL with .html#begin

    I made an error. I put CustomUrls.php also in the directory configuration.

    After I had corrected the error, it works !!

    Many thanks for your support.

    Bert

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •